<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>CGI - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link href="/static/css-20090925.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
        <div id="search_form">
          <form action="search.html" method="GET" id="search">
            <input type="text" name="q" id="search_box" alt="Search">
          </form>
        </div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a></li>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
          </div>
          <div class="side_group">
            <div class="side_panel links_panel">
              <p>News / Blogs</p>
              <ul>
        <li><a href="http://perlbuzz.com">Perl Buzz</a></li>
        <li><a href="http://ironman.enlightenedperl.org">Perl Iron Man</a></li>
        <li><a href="http://perlsphere.net">Perlsphere</a></li>
        <li><a href="http://planet.perl.org">Planet Perl</a></li>
	<li><a href="http://news.perlfoundation.org/">TPF news</a></li>
        <li><a href="http://use.perl.org">Use Perl</a></li>
              </ul>
            </div>            
            <div class="side_panel links_panel">
              <p>See also</p>
              <ul>
        <li><a href="http://search.cpan.org">CPAN</a></li>
        <li><a href="http://www.perl.org">Perl.org</a></li>
        <li><a href="http://www.perl.com">Perl.com</a></li>
        <li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
        <li><a href="http://jobs.perl.org">Perl Jobs</a></li>
        <li><a href="http://www.pm.org">Perl Mongers</a></li>
        <li><a href="http://www.perlmonks.org">Perl Monks</a></li>
              </ul>
            </div>
            <div class="side_panel links_panel">
              <p>Contact</p>
              <ul>
                <li><a href="http://perl.jonallen.info">Site designed and maintained by Jon&nbsp;Allen&nbsp;(JJ)</a>
                <li><a href="http://perl.jonallen.info">http://perl.jonallen.info</a>
              </ul>
              <ul>
                <li><a href="http://perl.jonallen.info/projects/perldoc">View the project page and FAQs</a>
              </ul>
            </div>
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>CGI</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 10.1 documentation
              </div>
              <div id="page_links">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
                  &bull; <a href="#" id="page_index_toggle">Show page index</a>
		
		
                  &bull; <a href="CGI.pdf">Download PDF</a>
		
              </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-modules-C.html">Core modules (C)</a> &gt;
      
    
    CGI
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>
	    <div id="from_search"></div>
            <h1>CGI</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#PROGRAMMING-STYLE">PROGRAMMING STYLE</a><li><a href="#CALLING-CGI.PM-ROUTINES">CALLING CGI.PM ROUTINES</a><li><a href="#CREATING-A-NEW-QUERY-OBJECT-(OBJECT-ORIENTED-STYLE)%3a">CREATING A NEW QUERY OBJECT (OBJECT-ORIENTED STYLE):</a><li><a href="#CREATING-A-NEW-QUERY-OBJECT-FROM-AN-INPUT-FILE">CREATING A NEW QUERY OBJECT FROM AN INPUT FILE</a><li><a href="#FETCHING-A-LIST-OF-KEYWORDS-FROM-THE-QUERY%3a">FETCHING A LIST OF KEYWORDS FROM THE QUERY:</a><li><a href="#FETCHING-THE-NAMES-OF-ALL-THE-PARAMETERS-PASSED-TO-YOUR-SCRIPT%3a">FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:</a><li><a href="#FETCHING-THE-VALUE-OR-VALUES-OF-A-SINGLE-NAMED-PARAMETER%3a">FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:</a><li><a href="#SETTING-THE-VALUE(S)-OF-A-NAMED-PARAMETER%3a">SETTING THE VALUE(S) OF A NAMED PARAMETER:</a><li><a href="#APPENDING-ADDITIONAL-VALUES-TO-A-NAMED-PARAMETER%3a">APPENDING ADDITIONAL VALUES TO A NAMED PARAMETER:</a><li><a href="#IMPORTING-ALL-PARAMETERS-INTO-A-NAMESPACE%3a">IMPORTING ALL PARAMETERS INTO A NAMESPACE:</a><li><a href="#DELETING-A-PARAMETER-COMPLETELY%3a">DELETING A PARAMETER COMPLETELY:</a><li><a href="#DELETING-ALL-PARAMETERS%3a">DELETING ALL PARAMETERS:</a><li><a href="#HANDLING-NON-URLENCODED-ARGUMENTS">HANDLING NON-URLENCODED ARGUMENTS</a><li><a href="#DIRECT-ACCESS-TO-THE-PARAMETER-LIST%3a">DIRECT ACCESS TO THE PARAMETER LIST:</a><li><a href="#FETCHING-THE-PARAMETER-LIST-AS-A-HASH%3a">FETCHING THE PARAMETER LIST AS A HASH:</a><li><a href="#SAVING-THE-STATE-OF-THE-SCRIPT-TO-A-FILE%3a">SAVING THE STATE OF THE SCRIPT TO A FILE:</a><li><a href="#RETRIEVING-CGI-ERRORS">RETRIEVING CGI ERRORS</a><li><a href="#USING-THE-FUNCTION-ORIENTED-INTERFACE">USING THE FUNCTION-ORIENTED INTERFACE</a><li><a href="#PRAGMAS">PRAGMAS</a><li><a href="#SPECIAL-FORMS-FOR-IMPORTING-HTML-TAG-FUNCTIONS">SPECIAL FORMS FOR IMPORTING HTML-TAG FUNCTIONS</a></ul><li><a href="#GENERATING-DYNAMIC-DOCUMENTS">GENERATING DYNAMIC DOCUMENTS</a><ul><li><a href="#CREATING-A-STANDARD-HTTP-HEADER%3a">CREATING A STANDARD HTTP HEADER:</a><li><a href="#GENERATING-A-REDIRECTION-HEADER">GENERATING A REDIRECTION HEADER</a><li><a href="#CREATING-THE-HTML-DOCUMENT-HEADER">CREATING THE HTML DOCUMENT HEADER</a><li><a href="#ENDING-THE-HTML-DOCUMENT%3a">ENDING THE HTML DOCUMENT:</a><li><a href="#CREATING-A-SELF-REFERENCING-URL-THAT-PRESERVES-STATE-INFORMATION%3a">CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION:</a><li><a href="#OBTAINING-THE-SCRIPT'S-URL">OBTAINING THE SCRIPT'S URL</a><li><a href="#MIXING-POST-AND-URL-PARAMETERS">MIXING POST AND URL PARAMETERS</a></ul><li><a href="#CREATING-STANDARD-HTML-ELEMENTS%3a">CREATING STANDARD HTML ELEMENTS:</a><ul><li><a href="#PROVIDING-ARGUMENTS-TO-HTML-SHORTCUTS">PROVIDING ARGUMENTS TO HTML SHORTCUTS</a><li><a href="#THE-DISTRIBUTIVE-PROPERTY-OF-HTML-SHORTCUTS">THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS</a><li><a href="#HTML-SHORTCUTS-AND-LIST-INTERPOLATION">HTML SHORTCUTS AND LIST INTERPOLATION</a><li><a href="#NON-STANDARD-HTML-SHORTCUTS">NON-STANDARD HTML SHORTCUTS</a><li><a href="#AUTOESCAPING-HTML">AUTOESCAPING HTML</a><li><a href="#PRETTY-PRINTING-HTML">PRETTY-PRINTING HTML</a></ul><li><a href="#CREATING-FILL-OUT-FORMS%3a">CREATING FILL-OUT FORMS:</a><ul><li><a href="#CREATING-AN-ISINDEX-TAG">CREATING AN ISINDEX TAG</a><li><a href="#STARTING-AND-ENDING-A-FORM">STARTING AND ENDING A FORM</a><li><a href="#FORM-ELEMENTS">FORM ELEMENTS</a><li><a href="#CREATING-A-TEXT-FIELD">CREATING A TEXT FIELD</a><li><a href="#CREATING-A-BIG-TEXT-FIELD">CREATING A BIG TEXT FIELD</a><li><a href="#CREATING-A-PASSWORD-FIELD">CREATING A PASSWORD FIELD</a><li><a href="#CREATING-A-FILE-UPLOAD-FIELD">CREATING A FILE UPLOAD FIELD</a><li><a href="#CREATING-A-POPUP-MENU">CREATING A POPUP MENU</a><li><a href="#CREATING-AN-OPTION-GROUP">CREATING AN OPTION GROUP</a><li><a href="#CREATING-A-SCROLLING-LIST">CREATING A SCROLLING LIST</a><li><a href="#CREATING-A-GROUP-OF-RELATED-CHECKBOXES">CREATING A GROUP OF RELATED CHECKBOXES</a><li><a href="#CREATING-A-STANDALONE-CHECKBOX">CREATING A STANDALONE CHECKBOX</a><li><a href="#CREATING-A-RADIO-BUTTON-GROUP">CREATING A RADIO BUTTON GROUP</a><li><a href="#CREATING-A-SUBMIT-BUTTON">CREATING A SUBMIT BUTTON</a><li><a href="#CREATING-A-RESET-BUTTON">CREATING A RESET BUTTON</a><li><a href="#CREATING-A-DEFAULT-BUTTON">CREATING A DEFAULT BUTTON</a><li><a href="#CREATING-A-HIDDEN-FIELD">CREATING A HIDDEN FIELD</a><li><a href="#CREATING-A-CLICKABLE-IMAGE-BUTTON">CREATING A CLICKABLE IMAGE BUTTON</a><li><a href="#CREATING-A-JAVASCRIPT-ACTION-BUTTON">CREATING A JAVASCRIPT ACTION BUTTON</a></ul><li><a href="#HTTP-COOKIES">HTTP COOKIES</a><li><a href="#WORKING-WITH-FRAMES">WORKING WITH FRAMES</a><li><a href="#SUPPORT-FOR-JAVASCRIPT">SUPPORT FOR JAVASCRIPT</a><li><a href="#LIMITED-SUPPORT-FOR-CASCADING-STYLE-SHEETS">LIMITED SUPPORT FOR CASCADING STYLE SHEETS</a><li><a href="#DEBUGGING">DEBUGGING</a><ul><li><a href="#DUMPING-OUT-ALL-THE-NAME%2fVALUE-PAIRS">DUMPING OUT ALL THE NAME/VALUE PAIRS</a></ul><li><a href="#FETCHING-ENVIRONMENT-VARIABLES">FETCHING ENVIRONMENT VARIABLES</a><li><a href="#USING-NPH-SCRIPTS">USING NPH SCRIPTS</a><li><a href="#Server-Push">Server Push</a><li><a href="#Avoiding-Denial-of-Service-Attacks">Avoiding Denial of Service Attacks</a><li><a href="#COMPATIBILITY-WITH-CGI-LIB.PL">COMPATIBILITY WITH CGI-LIB.PL</a><li><a href="#AUTHOR-INFORMATION">AUTHOR INFORMATION</a><li><a href="#CREDITS">CREDITS</a><li><a href="#A-COMPLETE-EXAMPLE-OF-A-SIMPLE-FORM-BASED-SCRIPT">A COMPLETE EXAMPLE OF A SIMPLE FORM-BASED SCRIPT</a><li><a href="#BUGS">BUGS</a><li><a href="#SEE-ALSO">SEE ALSO</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>CGI - Handle Common Gateway Interface requests and responses</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$q</span> = <span class="w">CGI</span><span class="w">-&gt;new</span><span class="sc">;</span></li><li></li><li>    <span class="c"># Process an HTTP request</span></li><li>     <span class="i">@values</span>  = <span class="i">$q</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;form_field&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>     <span class="i">$fh</span>      = <span class="i">$q</span><span class="i">-&gt;upload</span><span class="s">(</span><span class="q">&#39;file_field&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>     <span class="i">$riddle</span>  = <span class="i">$query</span><span class="i">-&gt;cookie</span><span class="s">(</span><span class="q">&#39;riddle_name&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>     <span class="i">%answers</span> = <span class="i">$query</span><span class="i">-&gt;cookie</span><span class="s">(</span><span class="q">&#39;answers&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>    <span class="c"># Prepare various HTTP responses</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span><span class="q">&#39;application/json&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	<span class="i">$cookie1</span> = <span class="i">$q</span><span class="i">-&gt;cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;riddle_name&#39;</span><span class="cm">,</span> -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&quot;The Sphynx&#39;s Question&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>	<span class="i">$cookie2</span> = <span class="i">$q</span><span class="i">-&gt;cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;answers&#39;</span><span class="cm">,</span> -<span class="w">value</span><span class="cm">=&gt;</span>\<span class="i">%answers</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span></li><li>        -<span class="w">type</span>    <span class="cm">=&gt;</span> <span class="q">&#39;image/gif&#39;</span><span class="cm">,</span></li><li>        -<span class="w">expires</span> <span class="cm">=&gt;</span> <span class="q">&#39;+3d&#39;</span><span class="cm">,</span></li><li>        -<span class="w">cookie</span>  <span class="cm">=&gt;</span> <span class="s">[</span><span class="i">$cookie1</span><span class="cm">,</span><span class="i">$cookie2</span><span class="s">]</span></li><li>        <span class="s">)</span><span class="sc">;</span></li><li></li><li>   <a class="l_k" href="functions/print.html">print</a>  <span class="i">$q</span><span class="i">-&gt;redirect</span><span class="s">(</span><span class="q">&#39;<a href="http://somewhere.else/in/movie/land">http://somewhere.else/in/movie/land</a>&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>CGI.pm is a stable, complete and mature solution for processing and preparing
HTTP requests and responses.  Major features including processing form
submissions, file uploads, reading and writing cookies, query string generation
and manipulation, and processing and preparing HTTP headers. Some HTML
generation utilities are included as well.</p>
<p>CGI.pm performs very well in in a vanilla CGI.pm environment and also comes
with built-in support for mod_perl and mod_perl2 as well as FastCGI.</p>
<p>It has the benefit of having developed and refined over 10 years with input
from dozens of contributors and being deployed on thousands of websites.
CGI.pm has been included in the Perl distribution since Perl 5.4, and has
become a de-facto standard.</p>
<a name="PROGRAMMING-STYLE"></a><h2>PROGRAMMING STYLE</h2>
<p>There are two styles of programming with CGI.pm, an object-oriented
style and a function-oriented style.  In the object-oriented style you
create one or more CGI objects and then use object methods to create
the various elements of the page.  Each CGI object starts out with the
list of named parameters that were passed to your CGI script by the
server.  You can modify the objects, save them to a file or database
and recreate them.  Because each object corresponds to the &quot;state&quot; of
the CGI script, and because each object&#39;s parameter list is
independent of the others, this allows you to save the state of the
script and restore it later.</p>
<p>For example, using the object oriented style, here is how you create
a simple &quot;Hello World&quot; HTML page:</p>
<pre class="verbatim"><ol><li>   <span class="c">#!/usr/local/bin/perl -w</span></li><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span><span class="sc">;</span>                             <span class="c"># load CGI routines</span></li><li>   <span class="i">$q</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span>                        <span class="c"># create new CGI object</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="cm">,</span>                    <span class="c"># create the HTTP header</span></li><li>         <span class="i">$q</span><span class="i">-&gt;start_html</span><span class="s">(</span><span class="q">&#39;hello world&#39;</span><span class="s">)</span><span class="cm">,</span> <span class="c"># start the HTML</span></li><li>         <span class="i">$q</span><span class="i">-&gt;h1</span><span class="s">(</span><span class="q">&#39;hello world&#39;</span><span class="s">)</span><span class="cm">,</span>         <span class="c"># level 1 header</span></li><li>         <span class="i">$q</span><span class="i">-&gt;end_html</span><span class="sc">;</span>                  <span class="c"># end the HTML</span></li></ol></pre><p>In the function-oriented style, there is one default CGI object that
you rarely deal with directly.  Instead you just call functions to
retrieve CGI parameters, create HTML tags, manage cookies, and so
on.  This provides you with a cleaner programming interface, but
limits you to using one CGI object at a time.  The following example
prints the same page, but uses the function-oriented interface.
The main differences are that we now need to import a set of functions
into our name space (usually the &quot;standard&quot; functions), and we don&#39;t
need to create the CGI object.</p>
<pre class="verbatim"><ol><li>   <span class="c">#!/usr/local/bin/perl</span></li><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard/</span><span class="sc">;</span>           <span class="c"># load standard CGI routines</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="cm">,</span>                    <span class="c"># create the HTTP header</span></li><li>         <span class="i">start_html</span><span class="s">(</span><span class="q">&#39;hello world&#39;</span><span class="s">)</span><span class="cm">,</span> <span class="c"># start the HTML</span></li><li>         <span class="i">h1</span><span class="s">(</span><span class="q">&#39;hello world&#39;</span><span class="s">)</span><span class="cm">,</span>         <span class="c"># level 1 header</span></li><li>         <span class="w">end_html</span><span class="sc">;</span>                  <span class="c"># end the HTML</span></li></ol></pre><p>The examples in this document mainly use the object-oriented style.
See HOW TO IMPORT FUNCTIONS for important information on
function-oriented programming in CGI.pm</p>
<a name="CALLING-CGI.PM-ROUTINES"></a><h2>CALLING CGI.PM ROUTINES</h2>
<p>Most CGI.pm routines accept several arguments, sometimes as many as 20
optional ones!  To simplify this interface, all routines use a named
argument calling style that looks like this:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;image/gif&#39;</span><span class="cm">,</span>-<span class="w">expires</span><span class="cm">=&gt;</span><span class="q">&#39;+3d&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Each argument name is preceded by a dash.  Neither case nor order
matters in the argument list.  -type, -Type, and -TYPE are all
acceptable.  In fact, only the first argument needs to begin with a
dash.  If a dash is present in the first argument, CGI.pm assumes
dashes for the subsequent ones.</p>
<p>Several routines are commonly called with just one argument.  In the
case of these routines you can provide the single argument without an
argument name.  header() happens to be one of these routines.  In this
case, the single argument is the document type.</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span><span class="q">&#39;text/html&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Other such routines are documented below.</p>
<p>Sometimes named arguments expect a scalar, sometimes a reference to an
array, and sometimes a reference to a hash.  Often, you can pass any
type of argument and the routine will do whatever is most appropriate.
For example, the param() routine is used to set a CGI parameter to a
single or a multi-valued value.  The two cases are shown below:</p>
<pre class="verbatim"><ol><li>   <span class="i">$q</span><span class="i">-&gt;param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;veggie&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;tomato&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="i">$q</span><span class="i">-&gt;param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;veggie&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;tomato&#39;</span><span class="cm">,</span><span class="q">&#39;tomahto&#39;</span><span class="cm">,</span><span class="q">&#39;potato&#39;</span><span class="cm">,</span><span class="q">&#39;potahto&#39;</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>A large number of routines in CGI.pm actually aren&#39;t specifically
defined in the module, but are generated automatically as needed.
These are the &quot;HTML shortcuts,&quot; routines that generate HTML tags for
use in dynamically-generated pages.  HTML tags have both attributes
(the attribute=&quot;value&quot; pairs within the tag itself) and contents (the
part between the opening and closing pairs.)  To distinguish between
attributes and contents, CGI.pm uses the convention of passing HTML
attributes as a hash reference as the first argument, and the
contents, if any, as any subsequent arguments.  It works out like
this:</p>
<pre class="verbatim"><ol><li>   Code                           Generated HTML</li><li>   ----                           --------------</li><li>   h1()                           &lt;h1&gt;</li><li>   h1('some','contents');         &lt;h1&gt;some contents&lt;/h1&gt;</li><li>   h1({-align=&gt;left});            &lt;h1 align="LEFT"&gt;</li><li>   h1({-align=&gt;left},'contents'); &lt;h1 align="LEFT"&gt;contents&lt;/h1&gt;</li></ol></pre><p>HTML tags are described in more detail later.</p>
<p>Many newcomers to CGI.pm are puzzled by the difference between the
calling conventions for the HTML shortcuts, which require curly braces
around the HTML tag attributes, and the calling conventions for other
routines, which manage to generate attributes without the curly
brackets.  Don&#39;t be confused.  As a convenience the curly braces are
optional in all but the HTML shortcuts.  If you like, you can use
curly braces when calling any routine that takes named arguments.  For
example:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span> <span class="s">{</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;image/gif&#39;</span><span class="cm">,</span>-<span class="w">expires</span><span class="cm">=&gt;</span><span class="q">&#39;+3d&#39;</span><span class="s">}</span> <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you use the <b>-w</b> switch, you will be warned that some CGI.pm argument
names conflict with built-in Perl functions.  The most frequent of
these is the -values argument, used to create multi-valued menus,
radio button clusters and the like.  To get around this warning, you
have several choices:</p>
<ol>
<li>
<p>Use another name for the argument, if one is available. 
For example, -value is an alias for -values.</p>
</li>
<li>
<p>Change the capitalization, e.g. -Values</p>
</li>
<li>
<p>Put quotes around the argument name, e.g. &#39;-values&#39;</p>
</li>
</ol>
<p>Many routines will do something useful with a named argument that it
doesn&#39;t recognize.  For example, you can produce non-standard HTTP
header fields by providing them as named arguments:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span>-<span class="w">type</span>  <span class="cm">=&gt;</span>  <span class="q">&#39;text/html&#39;</span><span class="cm">,</span></li><li>                   -<span class="w">cost</span>  <span class="cm">=&gt;</span>  <span class="q">&#39;Three smackers&#39;</span><span class="cm">,</span></li><li>                   -<span class="w">annoyance_level</span> <span class="cm">=&gt;</span> <span class="q">&#39;high&#39;</span><span class="cm">,</span></li><li>                   -<span class="w">complaints_to</span>   <span class="cm">=&gt;</span> <span class="q">&#39;bit bucket&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This will produce the following nonstandard HTTP header:</p>
<pre class="verbatim"><ol><li>   HTTP/1.0 200 OK</li><li>   Cost: Three smackers</li><li>   Annoyance-level: high</li><li>   Complaints-to: bit bucket</li><li>   Content-type: text/html</li></ol></pre><p>Notice the way that underscores are translated automatically into
hyphens.  HTML-generating routines perform a different type of
translation.</p>
<p>This feature allows you to keep up with the rapidly changing HTTP and
HTML &quot;standards&quot;.</p>
<a name="CREATING-A-NEW-QUERY-OBJECT-(OBJECT-ORIENTED-STYLE)%3a"></a><h2>CREATING A NEW QUERY OBJECT (OBJECT-ORIENTED STYLE):</h2>
<pre class="verbatim"><ol><li>     <span class="i">$query</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li></ol></pre><p>This will parse the input (from both POST and GET methods) and store
it into a perl5 object called $query.</p>
<p>Any filehandles from file uploads will have their position reset to 
the beginning of the file.</p>
<a name="CREATING-A-NEW-QUERY-OBJECT-FROM-AN-INPUT-FILE"></a><h2>CREATING A NEW QUERY OBJECT FROM AN INPUT FILE</h2>
<pre class="verbatim"><ol><li>     <span class="i">$query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span><span class="w">INPUTFILE</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you provide a file handle to the new() method, it will read
parameters from the file (or STDIN, or whatever).  The file can be in
any of the forms describing below under debugging (i.e. a series of
newline delimited TAG=VALUE pairs will work).  Conveniently, this type
of file is created by the save() method (see below).  Multiple records
can be saved and restored.</p>
<p>Perl purists will be pleased to know that this syntax accepts
references to file handles, or even references to filehandle globs,
which is the &quot;official&quot; way to pass a filehandle:</p>
<pre class="verbatim"><ol><li>    <span class="i">$query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span>\<span class="i">*STDIN</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>You can also initialize the CGI object with a FileHandle or IO::File
object.</p>
<p>If you are using the function-oriented interface and want to
initialize CGI state from a file handle, the way to do this is with
<b>restore_parameters()</b>.  This will (re)initialize the
default CGI object from the indicated file handle.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a> <span class="s">(</span><span class="w">IN</span><span class="cm">,</span><span class="q">&quot;test.in&quot;</span><span class="s">)</span> || <a class="l_k" href="functions/die.html">die</a><span class="sc">;</span></li><li>    <span class="i">restore_parameters</span><span class="s">(</span><span class="w">IN</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/close.html">close</a> <span class="w">IN</span><span class="sc">;</span></li></ol></pre><p>You can also initialize the query object from a hash
reference:</p>
<pre class="verbatim"><ol><li>    <span class="i">$query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span> <span class="s">{</span><span class="q">&#39;dinosaur&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;barney&#39;</span><span class="cm">,</span></li><li>		       <span class="q">&#39;song&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;I love you&#39;</span><span class="cm">,</span></li><li>		       <span class="q">&#39;friends&#39;</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">qw/Jessica George Nancy/</span><span class="s">]</span><span class="s">}</span></li><li>		    <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>or from a properly formatted, URL-escaped query string:</p>
<pre class="verbatim"><ol><li>    <span class="i">$query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span><span class="q">&#39;dinosaur=barney&amp;color=purple&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>or from a previously existing CGI object (currently this clones the
parameter list, but none of the other object-specific fields, such as
autoescaping):</p>
<pre class="verbatim"><ol><li>    <span class="i">$old_query</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>    <span class="i">$new_query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span><span class="i">$old_query</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>To create an empty query, initialize it from an empty string or hash:</p>
<pre class="verbatim"><ol><li>   <span class="i">$empty_query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span><span class="q">&quot;&quot;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>       -or-</li><li></li><li>   <span class="i">$empty_query</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span><span class="s">{</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="FETCHING-A-LIST-OF-KEYWORDS-FROM-THE-QUERY%3a"></a><h2>FETCHING A LIST OF KEYWORDS FROM THE QUERY:</h2>
<pre class="verbatim"><ol><li>     <span class="i">@keywords</span> = <span class="i">$query</span><span class="i">-&gt;keywords</span></li></ol></pre><p>If the script was invoked as the result of an &lt;ISINDEX&gt; search, the
parsed keywords can be obtained as an array using the keywords() method.</p>
<a name="FETCHING-THE-NAMES-OF-ALL-THE-PARAMETERS-PASSED-TO-YOUR-SCRIPT%3a"></a><h2>FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:</h2>
<pre class="verbatim"><ol><li>     <span class="i">@names</span> = <span class="i">$query</span><span class="i">-&gt;param</span></li></ol></pre><p>If the script was invoked with a parameter list
(e.g. &quot;name1=value1&amp;name2=value2&amp;name3=value3&quot;), the param() method
will return the parameter names as a list.  If the script was invoked
as an &lt;ISINDEX&gt; script and contains a string without ampersands
(e.g. &quot;value1+value2+value3&quot;) , there will be a single parameter named
&quot;keywords&quot; containing the &quot;+&quot;-delimited keywords.</p>
<p>NOTE: As of version 1.5, the array of parameter names returned will
be in the same order as they were submitted by the browser.
Usually this order is the same as the order in which the 
parameters are defined in the form (however, this isn&#39;t part
of the spec, and so isn&#39;t guaranteed).</p>
<a name="FETCHING-THE-VALUE-OR-VALUES-OF-A-SINGLE-NAMED-PARAMETER%3a"></a><h2>FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:</h2>
<pre class="verbatim"><ol><li>    <span class="i">@values</span> = <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	      -or-</li><li></li><li>    <span class="i">$value</span> = <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Pass the param() method a single argument to fetch the value of the
named parameter. If the parameter is multivalued (e.g. from multiple
selections in a scrolling list), you can ask to receive an array.  Otherwise
the method will return a single value.</p>
<p>If a value is not given in the query string, as in the queries
&quot;name1=&amp;name2=&quot;, it will be returned as an empty string.</p>
<p>If the parameter does not exist at all, then param() will return undef
in a scalar context, and the empty list in a list context.</p>
<a name="SETTING-THE-VALUE(S)-OF-A-NAMED-PARAMETER%3a"></a><h2>SETTING THE VALUE(S) OF A NAMED PARAMETER:</h2>
<pre class="verbatim"><ol><li>    <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span><span class="q">&#39;an&#39;</span><span class="cm">,</span><span class="q">&#39;array&#39;</span><span class="cm">,</span><span class="q">&#39;of&#39;</span><span class="cm">,</span><span class="q">&#39;values&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This sets the value for the named parameter &#39;foo&#39; to an array of
values.  This is one way to change the value of a field AFTER
the script has been invoked once before.  (Another way is with
the -override parameter accepted by all methods that generate
form elements.)</p>
<p>param() also recognizes a named parameter style of calling described
in more detail later:</p>
<pre class="verbatim"><ol><li>    <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span>-<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;an&#39;</span><span class="cm">,</span><span class="q">&#39;array&#39;</span><span class="cm">,</span><span class="q">&#39;of&#39;</span><span class="cm">,</span><span class="q">&#39;values&#39;</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>			      -or-</li><li></li><li>    <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;the value&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="APPENDING-ADDITIONAL-VALUES-TO-A-NAMED-PARAMETER%3a"></a><h2>APPENDING ADDITIONAL VALUES TO A NAMED PARAMETER:</h2>
<pre class="verbatim"><ol><li>   <span class="i">$query</span><span class="i">-&gt;append</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span>-<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;yet&#39;</span><span class="cm">,</span><span class="q">&#39;more&#39;</span><span class="cm">,</span><span class="q">&#39;values&#39;</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This adds a value or list of values to the named parameter.  The
values are appended to the end of the parameter if it already exists.
Otherwise the parameter is created.  Note that this method only
recognizes the named argument calling syntax.</p>
<a name="IMPORTING-ALL-PARAMETERS-INTO-A-NAMESPACE%3a"></a><h2>IMPORTING ALL PARAMETERS INTO A NAMESPACE:</h2>
<pre class="verbatim"><ol><li>   <span class="i">$query</span><span class="i">-&gt;import_names</span><span class="s">(</span><span class="q">&#39;R&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This creates a series of variables in the &#39;R&#39; namespace.  For example,
$R::foo, @R:foo.  For keyword lists, a variable @R::keywords will appear.
If no namespace is given, this method will assume &#39;Q&#39;.
WARNING:  don&#39;t import anything into &#39;main&#39;; this is a major security
risk!!!!</p>
<p>NOTE 1: Variable names are transformed as necessary into legal Perl
variable names.  All non-legal characters are transformed into
underscores.  If you need to keep the original names, you should use
the param() method instead to access CGI variables by name.</p>
<p>NOTE 2: In older versions, this method was called <b>import()</b>.  As of version 2.20, 
this name has been removed completely to avoid conflict with the built-in
Perl module <b>import</b> operator.</p>
<a name="DELETING-A-PARAMETER-COMPLETELY%3a"></a><h2>DELETING A PARAMETER COMPLETELY:</h2>
<pre class="verbatim"><ol><li>    <span class="i">$query</span><span class="i">-&gt;delete</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span><span class="q">&#39;bar&#39;</span><span class="cm">,</span><span class="q">&#39;baz&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This completely clears a list of parameters.  It sometimes useful for
resetting parameters that you don&#39;t want passed down between script
invocations.</p>
<p>If you are using the function call interface, use &quot;Delete()&quot; instead
to avoid conflicts with Perl&#39;s built-in delete operator.</p>
<a name="DELETING-ALL-PARAMETERS%3a"></a><h2>DELETING ALL PARAMETERS:</h2>
<pre class="verbatim"><ol><li>   <span class="i">$query</span><span class="i">-&gt;delete_all</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This clears the CGI object completely.  It might be useful to ensure
that all the defaults are taken when you create a fill-out form.</p>
<p>Use Delete_all() instead if you are using the function call interface.</p>
<a name="HANDLING-NON-URLENCODED-ARGUMENTS"></a><h2>HANDLING NON-URLENCODED ARGUMENTS</h2>
<p>If POSTed data is not of type application/x-www-form-urlencoded or
multipart/form-data, then the POSTed data will not be processed, but
instead be returned as-is in a parameter named POSTDATA.  To retrieve
it, use code like this:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$data</span> = <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;POSTDATA&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Likewise if PUTed data can be retrieved with code like this:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$data</span> = <span class="i">$query</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;PUTDATA&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>(If you don&#39;t know what the preceding means, don&#39;t worry about it.  It
only affects people trying to use CGI for XML processing and other
specialized tasks.)</p>
<a name="DIRECT-ACCESS-TO-THE-PARAMETER-LIST%3a"></a><h2>DIRECT ACCESS TO THE PARAMETER LIST:</h2>
<pre class="verbatim"><ol><li>   <span class="i">$q</span><span class="i">-&gt;param_fetch</span><span class="s">(</span><span class="q">&#39;address&#39;</span><span class="s">)</span>-&gt;[<span class="n">1</span>] = <span class="q">&#39;1313 Mockingbird Lane&#39;</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/unshift.html">unshift</a> <span class="i">@</span>{<span class="i">$q</span><span class="i">-&gt;param_fetch</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;address&#39;</span><span class="s">)</span>}<span class="cm">,</span><span class="q">&#39;George Munster&#39;</span><span class="sc">;</span></li></ol></pre><p>If you need access to the parameter list in a way that isn&#39;t covered
by the methods above, you can obtain a direct reference to it by
calling the <b>param_fetch()</b> method with the name of the .  This
will return an array reference to the named parameters, which you then
can manipulate in any way you like.</p>
<p>You can also use a named argument style using the <b>-name</b> argument.</p>
<a name="FETCHING-THE-PARAMETER-LIST-AS-A-HASH%3a"></a><h2>FETCHING THE PARAMETER LIST AS A HASH:</h2>
<pre class="verbatim"><ol><li>    <span class="i">$params</span> = <span class="i">$q</span><span class="i">-&gt;Vars</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$params</span>-&gt;{<span class="q">&#39;address&#39;</span>}<span class="sc">;</span></li><li>    <span class="i">@foo</span> = <a class="l_k" href="functions/split.html">split</a><span class="s">(</span><span class="q">&quot;\0&quot;</span><span class="cm">,</span><span class="i">$params</span>-&gt;{<span class="q">&#39;foo&#39;</span>}<span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">%params</span> = <span class="i">$q</span><span class="i">-&gt;Vars</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">&#39;:cgi-lib&#39;</span><span class="sc">;</span></li><li>    <span class="i">$params</span> = <span class="w">Vars</span><span class="sc">;</span></li></ol></pre><p>Many people want to fetch the entire parameter list as a hash in which
the keys are the names of the CGI parameters, and the values are the
parameters&#39; values.  The Vars() method does this.  Called in a scalar
context, it returns the parameter list as a tied hash reference.
Changing a key changes the value of the parameter in the underlying
CGI parameter list.  Called in a list context, it returns the
parameter list as an ordinary hash.  This allows you to read the
contents of the parameter list, but not to change it.</p>
<p>When using this, the thing you must watch out for are multivalued CGI
parameters.  Because a hash cannot distinguish between scalar and
list context, multivalued parameters will be returned as a packed
string, separated by the &quot;\0&quot; (null) character.  You must split this
packed string in order to get at the individual values.  This is the
convention introduced long ago by Steve Brenner in his cgi-lib.pl
module for Perl version 4.</p>
<p>If you wish to use Vars() as a function, import the <i>:cgi-lib</i> set of
function calls (also see the section on CGI-LIB compatibility).</p>
<a name="SAVING-THE-STATE-OF-THE-SCRIPT-TO-A-FILE%3a"></a><h2>SAVING THE STATE OF THE SCRIPT TO A FILE:</h2>
<pre class="verbatim"><ol><li>    <span class="i">$query</span><span class="i">-&gt;save</span><span class="s">(</span>\<span class="i">*FILEHANDLE</span><span class="s">)</span></li></ol></pre><p>This will write the current state of the form to the provided
filehandle.  You can read it back in by providing a filehandle
to the new() method.  Note that the filehandle can be a file, a pipe,
or whatever!</p>
<p>The format of the saved file is:</p>
<pre class="verbatim"><ol><li>	NAME1=VALUE1</li><li>	NAME1=VALUE1'</li><li>	NAME2=VALUE2</li><li>	NAME3=VALUE3</li><li>	=</li></ol></pre><p>Both name and value are URL escaped.  Multi-valued CGI parameters are
represented as repeated names.  A session record is delimited by a
single = symbol.  You can write out multiple records and read them
back in with several calls to <b>new</b>.  You can do this across several
sessions by opening the file in append mode, allowing you to create
primitive guest books, or to keep a history of users&#39; queries.  Here&#39;s
a short example of creating multiple session records:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span><span class="sc">;</span></li><li></li><li>   <a class="l_k" href="functions/open.html">open</a> <span class="s">(</span><span class="w">OUT</span><span class="cm">,</span><span class="q">&quot;&gt;&gt;test.out&quot;</span><span class="s">)</span> || <a class="l_k" href="functions/die.html">die</a><span class="sc">;</span></li><li>   <span class="i">$records</span> = <span class="n">5</span><span class="sc">;</span></li><li>   for <span class="s">(</span><span class="n">0</span>..<span class="i">$records</span><span class="s">)</span> <span class="s">{</span></li><li>       <a class="l_k" href="functions/my.html">my</a> <span class="i">$q</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>       <span class="i">$q</span><span class="i">-&gt;param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;counter&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="i">$_</span><span class="s">)</span><span class="sc">;</span></li><li>       <span class="i">$q</span><span class="i">-&gt;save</span><span class="s">(</span>\<span class="i">*OUT</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="s">}</span></li><li>   <a class="l_k" href="functions/close.html">close</a> <span class="w">OUT</span><span class="sc">;</span></li><li></li><li>   <span class="c"># reopen for reading</span></li><li>   <a class="l_k" href="functions/open.html">open</a> <span class="s">(</span><span class="w">IN</span><span class="cm">,</span><span class="q">&quot;test.out&quot;</span><span class="s">)</span> || <a class="l_k" href="functions/die.html">die</a><span class="sc">;</span></li><li>   while <span class="s">(</span>!<a class="l_k" href="functions/eof.html">eof</a><span class="s">(</span><span class="w">IN</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>       <a class="l_k" href="functions/my.html">my</a> <span class="i">$q</span> = <span class="w">new</span> <span class="i">CGI</span><span class="s">(</span>\<span class="i">*IN</span><span class="s">)</span><span class="sc">;</span></li><li>       <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;param</span><span class="s">(</span><span class="q">&#39;counter&#39;</span><span class="s">)</span><span class="cm">,</span><span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>   <span class="s">}</span></li></ol></pre><p>The file format used for save/restore is identical to that used by the
Whitehead Genome Center&#39;s data exchange format &quot;Boulderio&quot;, and can be
manipulated and even databased using Boulderio utilities.  See</p>
<pre class="verbatim"><ol><li>  http://stein.cshl.org/boulder/</li></ol></pre><p>for further details.</p>
<p>If you wish to use this method from the function-oriented (non-OO)
interface, the exported name for this method is <b>save_parameters()</b>.</p>
<a name="RETRIEVING-CGI-ERRORS"></a><h2>RETRIEVING CGI ERRORS</h2>
<p>Errors can occur while processing user input, particularly when
processing uploaded files.  When these errors occur, CGI will stop
processing and return an empty parameter list.  You can test for
the existence and nature of errors using the <i>cgi_error()</i> function.
The error messages are formatted as HTTP status codes. You can either
incorporate the error text into an HTML page, or use it as the value
of the HTTP status:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$error</span> = <span class="i">$q</span><span class="i">-&gt;cgi_error</span><span class="sc">;</span></li><li>    if <span class="s">(</span><span class="i">$error</span><span class="s">)</span> <span class="s">{</span></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;header</span><span class="s">(</span>-<span class="w">status</span><span class="cm">=&gt;</span><span class="i">$error</span><span class="s">)</span><span class="cm">,</span></li><li>	      <span class="i">$q</span><span class="i">-&gt;start_html</span><span class="s">(</span><span class="q">&#39;Problems&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>              <span class="i">$q</span><span class="i">-&gt;h2</span><span class="s">(</span><span class="q">&#39;Request not processed&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>	      <span class="i">$q</span><span class="i">-&gt;strong</span><span class="s">(</span><span class="i">$error</span><span class="s">)</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/exit.html">exit</a> <span class="n">0</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>When using the function-oriented interface (see the next section),
errors may only occur the first time you call <i>param()</i>. Be ready
for this!</p>
<a name="USING-THE-FUNCTION-ORIENTED-INTERFACE"></a><h2>USING THE FUNCTION-ORIENTED INTERFACE</h2>
<p>To use the function-oriented interface, you must specify which CGI.pm
routines or sets of routines to import into your script&#39;s namespace.
There is a small overhead associated with this importation, but it
isn&#39;t much.</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">&lt;list of methods&gt;</span><span class="sc">;</span></li></ol></pre><p>The listed methods will be imported into the current package; you can
call them directly without creating a CGI object first.  This example
shows how to import the <b>param()</b> and <b>header()</b>
methods, and then use them directly:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">&#39;param&#39;</span><span class="cm">,</span><span class="q">&#39;header&#39;</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span><span class="q">&#39;text/plain&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="i">$zipcode</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;zipcode&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>More frequently, you&#39;ll import common sets of functions by referring
to the groups by name.  All function sets are preceded with a &quot;:&quot;
character as in &quot;:html3&quot; (for tags defined in the HTML 3 standard).</p>
<p>Here is a list of the function sets you can import:</p>
<ul>
<li><a name="*%3acgi*"></a><b><b>:cgi</b></b>
<p>Import all CGI-handling methods, such as <b>param()</b>, <b>path_info()</b>
and the like.</p>
</li>
<li><a name="*%3aform*"></a><b><b>:form</b></b>
<p>Import all fill-out form generating methods, such as <b>textfield()</b>.</p>
</li>
<li><a name="*%3ahtml2*"></a><b><b>:html2</b></b>
<p>Import all methods that generate HTML 2.0 standard elements.</p>
</li>
<li><a name="*%3ahtml3*"></a><b><b>:html3</b></b>
<p>Import all methods that generate HTML 3.0 elements (such as
&lt;table&gt;, &lt;super&gt; and &lt;sub&gt;).</p>
</li>
<li><a name="*%3ahtml4*"></a><b><b>:html4</b></b>
<p>Import all methods that generate HTML 4 elements (such as
&lt;abbrev&gt;, &lt;acronym&gt; and &lt;thead&gt;).</p>
</li>
<li><a name="*%3anetscape*"></a><b><b>:netscape</b></b>
<p>Import all methods that generate Netscape-specific HTML extensions.</p>
</li>
<li><a name="*%3ahtml*"></a><b><b>:html</b></b>
<p>Import all HTML-generating shortcuts (i.e. &#39;html2&#39; + &#39;html3&#39; +
&#39;netscape&#39;)...</p>
</li>
<li><a name="*%3astandard*"></a><b><b>:standard</b></b>
<p>Import &quot;standard&quot; features, &#39;html2&#39;, &#39;html3&#39;, &#39;html4&#39;, &#39;form&#39; and &#39;cgi&#39;.</p>
</li>
<li><a name="*%3aall*"></a><b><b>:all</b></b>
<p>Import all the available methods.  For the full list, see the CGI.pm
code, where the variable %EXPORT_TAGS is defined.</p>
</li>
</ul>
<p>If you import a function name that is not part of CGI.pm, the module
will treat it as a new HTML tag and generate the appropriate
subroutine.  You can then use it like any other HTML tag.  This is to
provide for the rapidly-evolving HTML &quot;standard.&quot;  For example, say
Microsoft comes out with a new tag called &lt;gradient&gt; (which causes the
user&#39;s desktop to be flooded with a rotating gradient fill until his
machine reboots).  You don&#39;t need to wait for a new version of CGI.pm
to start using it immediately:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard :html3 gradient/</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">gradient</span><span class="s">(</span><span class="s">{</span>-<span class="w">start</span><span class="cm">=&gt;</span><span class="q">&#39;red&#39;</span><span class="cm">,</span>-<span class="w">end</span><span class="cm">=&gt;</span><span class="q">&#39;blue&#39;</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Note that in the interests of execution speed CGI.pm does <b>not</b> use
the standard <a href="Exporter.html">Exporter</a> syntax for specifying load symbols.  This may
change in the future.</p>
<p>If you import any of the state-maintaining CGI or form-generating
methods, a default CGI object will be created and initialized
automatically the first time you use any of the methods that require
one to be present.  This includes <b>param()</b>, <b>textfield()</b>,
<b>submit()</b> and the like.  (If you need direct access to the CGI
object, you can find it in the global variable <b>$CGI::Q</b>).  By
importing CGI.pm methods, you can create visually elegant scripts:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard/</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> </li><li>       <span class="i">header</span><span class="cm">,</span></li><li>       <span class="i">start_html</span><span class="s">(</span><span class="q">&#39;Simple Script&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>       <span class="i">h1</span><span class="s">(</span><span class="q">&#39;Simple Script&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>       <span class="w">start_form</span><span class="cm">,</span></li><li>       <span class="q">&quot;What&#39;s your name? &quot;</span><span class="cm">,</span><span class="i">textfield</span><span class="s">(</span><span class="q">&#39;name&#39;</span><span class="s">)</span><span class="cm">,</span><span class="w">p</span><span class="cm">,</span></li><li>       <span class="q">&quot;What&#39;s the combination?&quot;</span><span class="cm">,</span></li><li>       <span class="i">checkbox_group</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;words&#39;</span><span class="cm">,</span></li><li>		      -<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>		      -<span class="w">defaults</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="s">)</span><span class="cm">,</span><span class="w">p</span><span class="cm">,</span></li><li>       <span class="q">&quot;What&#39;s your favorite color?&quot;</span><span class="cm">,</span></li><li>       <span class="i">popup_menu</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;color&#39;</span><span class="cm">,</span></li><li>		  -<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;red&#39;</span><span class="cm">,</span><span class="q">&#39;green&#39;</span><span class="cm">,</span><span class="q">&#39;blue&#39;</span><span class="cm">,</span><span class="q">&#39;chartreuse&#39;</span><span class="s">]</span><span class="s">)</span><span class="cm">,</span><span class="w">p</span><span class="cm">,</span></li><li>       <span class="w">submit</span><span class="cm">,</span></li><li>       <span class="w">end_form</span><span class="cm">,</span></li><li>       <span class="w">hr</span><span class="cm">,</span><span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li></li><li>    if <span class="s">(</span><span class="w">param</span><span class="s">)</span> <span class="s">{</span></li><li>       <a class="l_k" href="functions/print.html">print</a> </li><li>	   <span class="q">&quot;Your name is &quot;</span><span class="cm">,</span><span class="i">em</span><span class="s">(</span><span class="i">param</span><span class="s">(</span><span class="q">&#39;name&#39;</span><span class="s">)</span><span class="s">)</span><span class="cm">,</span><span class="w">p</span><span class="cm">,</span></li><li>	   <span class="q">&quot;The keywords are: &quot;</span><span class="cm">,</span><span class="i">em</span><span class="s">(</span><a class="l_k" href="functions/join.html">join</a><span class="s">(</span><span class="q">&quot;, &quot;</span><span class="cm">,</span><span class="i">param</span><span class="s">(</span><span class="q">&#39;words&#39;</span><span class="s">)</span><span class="s">)</span><span class="s">)</span><span class="cm">,</span><span class="w">p</span><span class="cm">,</span></li><li>	   <span class="q">&quot;Your favorite color is &quot;</span><span class="cm">,</span><span class="i">em</span><span class="s">(</span><span class="i">param</span><span class="s">(</span><span class="q">&#39;color&#39;</span><span class="s">)</span><span class="s">)</span><span class="cm">,</span><span class="q">&quot;.\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">end_html</span><span class="sc">;</span></li></ol></pre><a name="PRAGMAS"></a><h2>PRAGMAS</h2>
<p>In addition to the function sets, there are a number of pragmas that
you can import.  Pragmas, which are always preceded by a hyphen,
change the way that CGI.pm functions in various ways.  Pragmas,
function sets, and individual functions can all be imported in the
same use() line.  For example, the following use statement imports the
standard set of functions and enables debugging mode (pragma
-debug):</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard -debug/</span><span class="sc">;</span></li></ol></pre><p>The current list of pragmas is as follows:</p>
<ul>
<li><a name="-any"></a><b>-any</b>
<p>When you <i>use CGI -any</i>, then any method that the query object
doesn&#39;t recognize will be interpreted as a new HTML tag.  This allows
you to support the next <i>ad hoc</i> Netscape or Microsoft HTML
extension.  This lets you go wild with new and unsupported tags:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw(-any)</span><span class="sc">;</span></li><li>   <span class="i">$q</span>=<span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;gradient</span><span class="s">(</span><span class="s">{</span><span class="w">speed</span><span class="cm">=&gt;</span><span class="q">&#39;fast&#39;</span><span class="cm">,</span><span class="w">start</span><span class="cm">=&gt;</span><span class="q">&#39;red&#39;</span><span class="cm">,</span><span class="w">end</span><span class="cm">=&gt;</span><span class="q">&#39;blue&#39;</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Since using &lt;cite&gt;any&lt;/cite&gt; causes any mistyped method name
to be interpreted as an HTML tag, use it with care or not at
all.</p>
</li>
<li><a name="-compile"></a><b>-compile</b>
<p>This causes the indicated autoloaded methods to be compiled up front,
rather than deferred to later.  This is useful for scripts that run
for an extended period of time under FastCGI or mod_perl, and for
those destined to be crunched by Malcolm Beattie&#39;s Perl compiler.  Use
it in conjunction with the methods or method families you plan to use.</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw(-compile :standard :html3)</span><span class="sc">;</span></li></ol></pre><p>or even</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw(-compile :all)</span><span class="sc">;</span></li></ol></pre><p>Note that using the -compile pragma in this way will always have
the effect of importing the compiled functions into the current
namespace.  If you want to compile without importing use the
compile() method instead:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="i">CGI</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="w">CGI</span><span class="w">-&gt;compile</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This is particularly useful in a mod_perl environment, in which you
might want to precompile all CGI routines in a startup script, and
then import the functions individually in each mod_perl script.</p>
</li>
<li><a name="-nosticky"></a><b>-nosticky</b>
<p>By default the CGI module implements a state-preserving behavior
called &quot;sticky&quot; fields.  The way this works is that if you are
regenerating a form, the methods that generate the form field values
will interrogate param() to see if similarly-named parameters are
present in the query string. If they find a like-named parameter, they
will use it to set their default values.</p>
<p>Sometimes this isn&#39;t what you want.  The <b>-nosticky</b> pragma prevents
this behavior.  You can also selectively change the sticky behavior in
each element that you generate.</p>
</li>
<li><a name="-tabindex"></a><b>-tabindex</b>
<p>Automatically add tab index attributes to each form field. With this
option turned off, you can still add tab indexes manually by passing a
-tabindex option to each field-generating method.</p>
</li>
<li><a name="-no_undef_params"></a><b>-no_undef_params</b>
<p>This keeps CGI.pm from including undef params in the parameter list.</p>
</li>
<li><a name="-no_xhtml"></a><b>-no_xhtml</b>
<p>By default, CGI.pm versions 2.69 and higher emit XHTML
(<a href="http://www.w3.org/TR/xhtml1/">http://www.w3.org/TR/xhtml1/</a>).  The -no_xhtml pragma disables this
feature.  Thanks to Michalis Kabrianis &lt;kabrianis@hellug.gr&gt; for this
feature.</p>
<p>If start_html()&#39;s -dtd parameter specifies an HTML 2.0 or 3.2 DTD, 
XHTML will automatically be disabled without needing to use this 
pragma.</p>
</li>
<li><a name="-utf8"></a><b>-utf8</b>
<p>This makes CGI.pm treat all parameters as UTF-8 strings. Use this with
care, as it will interfere with the processing of binary uploads. It
is better to manually select which fields are expected to return utf-8
strings and convert them using code like this:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$arg</span> = <span class="w">decode</span> <span class="w">utf8</span><span class="cm">=&gt;</span><span class="i">param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="-nph"></a><b>-nph</b>
<p>This makes CGI.pm produce a header appropriate for an NPH (no
parsed header) script.  You may need to do other things as well
to tell the server that the script is NPH.  See the discussion
of NPH scripts below.</p>
</li>
<li><a name="-newstyle_urls"></a><b>-newstyle_urls</b>
<p>Separate the name=value pairs in CGI parameter query strings with
semicolons rather than ampersands.  For example:</p>
<pre class="verbatim"><ol><li>   ?name=fred;age=24;favorite_color=3</li></ol></pre><p>Semicolon-delimited query strings are always accepted, but will not be
emitted by self_url() and query_string() unless the -newstyle_urls
pragma is specified.</p>
<p>This became the default in version 2.64.</p>
</li>
<li><a name="-oldstyle_urls"></a><b>-oldstyle_urls</b>
<p>Separate the name=value pairs in CGI parameter query strings with
ampersands rather than semicolons.  This is no longer the default.</p>
</li>
<li><a name="-autoload"></a><b>-autoload</b>
<p>This overrides the autoloader so that any function in your program
that is not recognized is referred to CGI.pm for possible evaluation.
This allows you to use all the CGI.pm functions without adding them to
your symbol table, which is of concern for mod_perl users who are
worried about memory consumption.  <i>Warning:</i> when
<i>-autoload</i> is in effect, you cannot use &quot;poetry mode&quot;
(functions without the parenthesis).  Use <i>hr()</i> rather
than <i>hr</i>, or add something like <i>use subs qw/hr p header/</i> 
to the top of your script.</p>
</li>
<li><a name="-no_debug"></a><b>-no_debug</b>
<p>This turns off the command-line processing features.  If you want to
run a CGI.pm script from the command line to produce HTML, and you
don&#39;t want it to read CGI parameters from the command line or STDIN,
then use this pragma:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw(-no_debug :standard)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="-debug"></a><b>-debug</b>
<p>This turns on full debugging.  In addition to reading CGI arguments
from the command-line processing, CGI.pm will pause and try to read
arguments from STDIN, producing the message &quot;(offline mode: enter
name=value pairs on standard input)&quot; features.</p>
<p>See the section on debugging for more details.</p>
</li>
<li><a name="-private_tempfiles"></a><b>-private_tempfiles</b>
<p>CGI.pm can process uploaded file. Ordinarily it spools the uploaded
file to a temporary directory, then deletes the file when done.
However, this opens the risk of eavesdropping as described in the file
upload section.  Another CGI script author could peek at this data
during the upload, even if it is confidential information. On Unix
systems, the -private_tempfiles pragma will cause the temporary file
to be unlinked as soon as it is opened and before any data is written
into it, reducing, but not eliminating the risk of eavesdropping
(there is still a potential race condition).  To make life harder for
the attacker, the program chooses tempfile names by calculating a 32
bit checksum of the incoming HTTP headers.</p>
<p>To ensure that the temporary file cannot be read by other CGI scripts,
use suEXEC or a CGI wrapper program to run your script.  The temporary
file is created with mode 0600 (neither world nor group readable).</p>
<p>The temporary directory is selected using the following algorithm:</p>
<pre class="verbatim"><ol><li>    1. if the current user (e.g. "nobody") has a directory named</li><li>    "tmp" in its home directory, use that (Unix systems only).</li><li></li><li>    2. if the environment variable TMPDIR exists, use the location</li><li>    indicated.</li><li></li><li>    3. Otherwise try the locations /usr/tmp, /var/tmp, C:\temp,</li><li>    /tmp, /temp, ::Temporary Items, and \WWW_ROOT.</li></ol></pre><p>Each of these locations is checked that it is a directory and is
writable.  If not, the algorithm tries the next choice.</p>
</li>
</ul>
<a name="SPECIAL-FORMS-FOR-IMPORTING-HTML-TAG-FUNCTIONS"></a><h2>SPECIAL FORMS FOR IMPORTING HTML-TAG FUNCTIONS</h2>
<p>Many of the methods generate HTML tags.  As described below, tag
functions automatically generate both the opening and closing tags.
For example:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">h1</span><span class="s">(</span><span class="q">&#39;Level 1 Header&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>produces</p>
<pre class="verbatim"><ol><li>  &lt;h1&gt;Level 1 Header&lt;/h1&gt;</li></ol></pre><p>There will be some times when you want to produce the start and end
tags yourself.  In this case, you can use the form start_<i>tag_name</i>
and end_<i>tag_name</i>, as in:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">start_h1</span><span class="cm">,</span><span class="q">&#39;Level 1 Header&#39;</span><span class="cm">,</span><span class="w">end_h1</span><span class="sc">;</span></li></ol></pre><p>With a few exceptions (described below), start_<i>tag_name</i> and
end_<i>tag_name</i> functions are not generated automatically when you
<i>use CGI</i>.  However, you can specify the tags you want to generate
<i>start/end</i> functions for by putting an asterisk in front of their
name, or, alternatively, requesting either &quot;start_<i>tag_name</i>&quot; or
&quot;end_<i>tag_name</i>&quot; in the import list.</p>
<p>Example:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard *table start_ul/</span><span class="sc">;</span></li></ol></pre><p>In this example, the following functions are generated in addition to
the standard ones:</p>
<ol>
<li><a name="1.-start_table()-(generates-a-%3ctable%3e-tag)"></a><b>start_table() (generates a &lt;table&gt; tag)</b>
</li>
<li><a name="2.-end_table()-(generates-a-%3c%2ftable%3e-tag)"></a><b>end_table() (generates a &lt;/table&gt; tag)</b>
</li>
<li><a name="3.-start_ul()-(generates-a-%3cul%3e-tag)"></a><b>start_ul() (generates a &lt;ul&gt; tag)</b>
</li>
<li><a name="4.-end_ul()-(generates-a-%3c%2ful%3e-tag)"></a><b>end_ul() (generates a &lt;/ul&gt; tag)</b>
</li>
</ol>
<a name="GENERATING-DYNAMIC-DOCUMENTS"></a><h1>GENERATING DYNAMIC DOCUMENTS</h1>
<p>Most of CGI.pm&#39;s functions deal with creating documents on the fly.
Generally you will produce the HTTP header first, followed by the
document itself.  CGI.pm provides functions for generating HTTP
headers of various types as well as for generating HTML.  For creating
GIF images, see the GD.pm module.</p>
<p>Each of these functions produces a fragment of HTML or HTTP which you
can print out directly so that it displays in the browser window,
append to a string, or save to a file for later use.</p>
<a name="CREATING-A-STANDARD-HTTP-HEADER%3a"></a><h2>CREATING A STANDARD HTTP HEADER:</h2>
<p>Normally the first thing you will do in any CGI script is print out an
HTTP header.  This tells the browser what type of document to expect,
and gives other optional information, such as the language, expiration
date, and whether to cache the document.  The header can also be
manipulated for special purposes, such as server push and pay per view
pages.</p>
<pre class="verbatim"><ol><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="sc">;</span></li><li></li><li>	     -or-</li><li></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span><span class="q">&#39;image/gif&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	     -or-</li><li></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span><span class="q">&#39;text/html&#39;</span><span class="cm">,</span><span class="q">&#39;204 No response&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	     -or-</li><li></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;image/gif&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">nph</span><span class="cm">=&gt;</span><span class="n">1</span><span class="cm">,</span></li><li>			     -<span class="w">status</span><span class="cm">=&gt;</span><span class="q">&#39;402 Payment required&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">expires</span><span class="cm">=&gt;</span><span class="q">&#39;+3d&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">cookie</span><span class="cm">=&gt;</span><span class="i">$cookie</span><span class="cm">,</span></li><li>                             -<span class="w">charset</span><span class="cm">=&gt;</span><span class="q">&#39;utf-7&#39;</span><span class="cm">,</span></li><li>                             -<span class="w">attachment</span><span class="cm">=&gt;</span><span class="q">&#39;foo.gif&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">Cost</span><span class="cm">=&gt;</span><span class="q">&#39;$2.00&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>header() returns the Content-type: header.  You can provide your own
MIME type if you choose, otherwise it defaults to text/html.  An
optional second parameter specifies the status code and a human-readable
message.  For example, you can specify 204, &quot;No response&quot; to create a
script that tells the browser to do nothing at all.</p>
<p>The last example shows the named argument style for passing arguments
to the CGI methods using named parameters.  Recognized parameters are
<b>-type</b>, <b>-status</b>, <b>-expires</b>, and <b>-cookie</b>.  Any other named
parameters will be stripped of their initial hyphens and turned into
header fields, allowing you to specify any HTTP header you desire.
Internal underscores will be turned into hyphens:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">Content_length</span><span class="cm">=&gt;</span><span class="n">3002</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Most browsers will not cache the output from CGI scripts.  Every time
the browser reloads the page, the script is invoked anew.  You can
change this behavior with the <b>-expires</b> parameter.  When you specify
an absolute or relative expiration interval with this parameter, some
browsers and proxy servers will cache the script&#39;s output until the
indicated expiration date.  The following forms are all valid for the
-expires field:</p>
<pre class="verbatim"><ol><li>	+30s                              30 seconds from now</li><li>	+10m                              ten minutes from now</li><li>	+1h                               one hour from now</li><li>	-1d                               yesterday (i.e. "ASAP!")</li><li>	now                               immediately</li><li>	+3M                               in three months</li><li>	+10y                              in ten years time</li><li>	Thursday, 25-Apr-1999 00:40:33 GMT  at the indicated time &amp; date</li></ol></pre><p>The <b>-cookie</b> parameter generates a header that tells the browser to provide
a &quot;magic cookie&quot; during all subsequent transactions with your script.
Netscape cookies have a special format that includes interesting attributes
such as expiration time.  Use the cookie() method to create and retrieve
session cookies.</p>
<p>The <b>-nph</b> parameter, if set to a true value, will issue the correct
headers to work with a NPH (no-parse-header) script.  This is important
to use with certain servers that expect all their scripts to be NPH.</p>
<p>The <b>-charset</b> parameter can be used to control the character set
sent to the browser.  If not provided, defaults to ISO-8859-1.  As a
side effect, this sets the charset() method as well.</p>
<p>The <b>-attachment</b> parameter can be used to turn the page into an
attachment.  Instead of displaying the page, some browsers will prompt
the user to save it to disk.  The value of the argument is the
suggested name for the saved file.  In order for this to work, you may
have to set the <b>-type</b> to &quot;application/octet-stream&quot;.</p>
<p>The <b>-p3p</b> parameter will add a P3P tag to the outgoing header.  The
parameter can be an arrayref or a space-delimited string of P3P tags.
For example:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">p3p</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">qw(CAO DSP LAW CURa)</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">p3p</span><span class="cm">=&gt;</span><span class="q">&#39;CAO DSP LAW CURa&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>In either case, the outgoing header will be formatted as:</p>
<pre class="verbatim"><ol><li>  P3P: policyref="/w3c/p3p.xml" cp="CAO DSP LAW CURa"</li></ol></pre><a name="GENERATING-A-REDIRECTION-HEADER"></a><h2>GENERATING A REDIRECTION HEADER</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">redirect</span><span class="s">(</span><span class="q">&#39;<a href="http://somewhere.else/in/movie/land">http://somewhere.else/in/movie/land</a>&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Sometimes you don&#39;t want to produce a document yourself, but simply
redirect the browser elsewhere, perhaps choosing a URL based on the
time of day or the identity of the user.</p>
<p>The redirect() function redirects the browser to a different URL.  If
you use redirection like this, you should <b>not</b> print out a header as
well.</p>
<p>You should always use full URLs (including the http: or ftp: part) in
redirection requests.  Relative URLs will not work correctly.</p>
<p>You can also use named arguments:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">redirect</span><span class="s">(</span>-<span class="w">uri</span><span class="cm">=&gt;</span><span class="q">&#39;<a href="http://somewhere.else/in/movie/land">http://somewhere.else/in/movie/land</a>&#39;</span><span class="cm">,</span></li><li>			   -<span class="w">nph</span><span class="cm">=&gt;</span><span class="n">1</span><span class="cm">,</span></li><li>                           -<span class="w">status</span><span class="cm">=&gt;</span><span class="n">301</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The <b>-nph</b> parameter, if set to a true value, will issue the correct
headers to work with a NPH (no-parse-header) script.  This is important
to use with certain servers, such as Microsoft IIS, which
expect all their scripts to be NPH.</p>
<p>The <b>-status</b> parameter will set the status of the redirect.  HTTP
defines three different possible redirection status codes:</p>
<pre class="verbatim"><ol><li>     301 Moved Permanently</li><li>     302 Found</li><li>     303 See Other</li></ol></pre><p>The default if not specified is 302, which means &quot;moved temporarily.&quot;
You may change the status to another status code if you wish.  Be
advised that changing the status to anything other than 301, 302 or
303 will probably break redirection.</p>
<a name="CREATING-THE-HTML-DOCUMENT-HEADER"></a><h2>CREATING THE HTML DOCUMENT HEADER</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">start_html</span><span class="s">(</span>-<span class="w">title</span><span class="cm">=&gt;</span><span class="q">&#39;Secrets of the Pyramids&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">author</span><span class="cm">=&gt;</span><span class="q">&#39;fred@capricorn.org&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">base</span><span class="cm">=&gt;</span><span class="q">&#39;true&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">target</span><span class="cm">=&gt;</span><span class="q">&#39;_blank&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">meta</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;keywords&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;pharaoh secret mummy&#39;</span><span class="cm">,</span></li><li>				    <span class="q">&#39;copyright&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;copyright 1996 King Tut&#39;</span><span class="s">}</span><span class="cm">,</span></li><li>			    -<span class="w">style</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;src&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;/styles/style1.css&#39;</span><span class="s">}</span><span class="cm">,</span></li><li>			    -<span class="w">BGCOLOR</span><span class="cm">=&gt;</span><span class="q">&#39;blue&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>After creating the HTTP header, most CGI scripts will start writing
out an HTML document.  The start_html() routine creates the top of the
page, along with a lot of optional information that controls the
page&#39;s appearance and behavior.</p>
<p>This method returns a canned HTML header and the opening &lt;body&gt; tag.
All parameters are optional.  In the named parameter form, recognized
parameters are -title, -author, -base, -xbase, -dtd, -lang and -target
(see below for the explanation).  Any additional parameters you
provide, such as the Netscape unofficial BGCOLOR attribute, are added
to the &lt;body&gt; tag.  Additional parameters must be proceeded by a
hyphen.</p>
<p>The argument <b>-xbase</b> allows you to provide an HREF for the &lt;base&gt; tag
different from the current location, as in</p>
<pre class="verbatim"><ol><li>    -<span class="w">xbase</span><span class="cm">=&gt;</span><span class="q">&quot;<a href="http://home.mcom.com/">http://home.mcom.com/</a>&quot;</span></li></ol></pre><p>All relative links will be interpreted relative to this tag.</p>
<p>The argument <b>-target</b> allows you to provide a default target frame
for all the links and fill-out forms on the page.  <b>This is a
non-standard HTTP feature which only works with Netscape browsers!</b>
See the Netscape documentation on frames for details of how to
manipulate this.</p>
<pre class="verbatim"><ol><li>    -<span class="w">target</span><span class="cm">=&gt;</span><span class="q">&quot;answer_window&quot;</span></li></ol></pre><p>All relative links will be interpreted relative to this tag.
You add arbitrary meta information to the header with the <b>-meta</b>
argument.  This argument expects a reference to a hash
containing name/value pairs of meta information.  These will be turned
into a series of header &lt;meta&gt; tags that look something like this:</p>
<pre class="verbatim"><ol><li>    &lt;meta name="keywords" content="pharaoh secret mummy"&gt;</li><li>    &lt;meta name="description" content="copyright 1996 King Tut"&gt;</li></ol></pre><p>To create an HTTP-EQUIV type of &lt;meta&gt; tag, use <b>-head</b>, described
below.</p>
<p>The <b>-style</b> argument is used to incorporate cascading stylesheets
into your code.  See the section on CASCADING STYLESHEETS for more
information.</p>
<p>The <b>-lang</b> argument is used to incorporate a language attribute into
the &lt;html&gt; tag.  For example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;start_html</span><span class="s">(</span>-<span class="w">lang</span><span class="cm">=&gt;</span><span class="q">&#39;fr-CA&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The default if not specified is &quot;en-US&quot; for US English, unless the 
-dtd parameter specifies an HTML 2.0 or 3.2 DTD, in which case the
lang attribute is left off.  You can force the lang attribute to left
off in other cases by passing an empty string (-lang=&gt;&#39;&#39;).</p>
<p>The <b>-encoding</b> argument can be used to specify the character set for
XHTML.  It defaults to iso-8859-1 if not specified.</p>
<p>The <b>-declare_xml</b> argument, when used in conjunction with XHTML,
will put a &lt;?xml&gt; declaration at the top of the HTML header. The sole
purpose of this declaration is to declare the character set
encoding. In the absence of -declare_xml, the output HTML will contain
a &lt;meta&gt; tag that specifies the encoding, allowing the HTML to pass
most validators.  The default for -declare_xml is false.</p>
<p>You can place other arbitrary HTML elements to the &lt;head&gt; section with the
<b>-head</b> tag.  For example, to place the rarely-used &lt;link&gt; element in the
head section, use this:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">start_html</span><span class="s">(</span>-<span class="w">head</span><span class="cm">=&gt;</span><span class="i">Link</span><span class="s">(</span><span class="s">{</span>-<span class="w">rel</span><span class="cm">=&gt;</span><span class="q">&#39;next&#39;</span><span class="cm">,</span></li><li>		                  -<span class="w">href</span><span class="cm">=&gt;</span><span class="q">&#39;<a href="http://www.capricorn.com/s2.html">http://www.capricorn.com/s2.html</a>&#39;</span><span class="s">}</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>To incorporate multiple HTML elements into the &lt;head&gt; section, just pass an
array reference:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">start_html</span><span class="s">(</span>-<span class="w">head</span><span class="cm">=&gt;</span><span class="s">[</span> </li><li>                             <span class="i">Link</span><span class="s">(</span><span class="s">{</span>-<span class="w">rel</span><span class="cm">=&gt;</span><span class="q">&#39;next&#39;</span><span class="cm">,</span></li><li>				   -<span class="w">href</span><span class="cm">=&gt;</span><span class="q">&#39;<a href="http://www.capricorn.com/s2.html">http://www.capricorn.com/s2.html</a>&#39;</span><span class="s">}</span><span class="s">)</span><span class="cm">,</span></li><li>		             <span class="i">Link</span><span class="s">(</span><span class="s">{</span>-<span class="w">rel</span><span class="cm">=&gt;</span><span class="q">&#39;previous&#39;</span><span class="cm">,</span></li><li>				   -<span class="w">href</span><span class="cm">=&gt;</span><span class="q">&#39;<a href="http://www.capricorn.com/s1.html">http://www.capricorn.com/s1.html</a>&#39;</span><span class="s">}</span><span class="s">)</span></li><li>			     <span class="s">]</span></li><li>		     <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>And here&#39;s how to create an HTTP-EQUIV &lt;meta&gt; tag:</p>
<pre class="verbatim"><ol><li>      <a class="l_k" href="functions/print.html">print</a> <span class="i">start_html</span><span class="s">(</span>-<span class="w">head</span><span class="cm">=&gt;</span><span class="i">meta</span><span class="s">(</span><span class="s">{</span>-<span class="w">http_equiv</span> <span class="cm">=&gt;</span> <span class="q">&#39;Content-Type&#39;</span><span class="cm">,</span></li><li>                                    -<span class="w">content</span>    <span class="cm">=&gt;</span> <span class="q">&#39;text/html&#39;</span><span class="s">}</span><span class="s">)</span><span class="s">)</span></li></ol></pre><p>JAVASCRIPTING: The <b>-script</b>, <b>-noScript</b>, <b>-onLoad</b>,
<b>-onMouseOver</b>, <b>-onMouseOut</b> and <b>-onUnload</b> parameters are used
to add Netscape JavaScript calls to your pages.  <b>-script</b> should
point to a block of text containing JavaScript function definitions.
This block will be placed within a &lt;script&gt; block inside the HTML (not
HTTP) header.  The block is placed in the header in order to give your
page a fighting chance of having all its JavaScript functions in place
even if the user presses the stop button before the page has loaded
completely.  CGI.pm attempts to format the script in such a way that
JavaScript-naive browsers will not choke on the code: unfortunately
there are some browsers, such as Chimera for Unix, that get confused
by it nevertheless.</p>
<p>The <b>-onLoad</b> and <b>-onUnload</b> parameters point to fragments of JavaScript
code to execute when the page is respectively opened and closed by the
browser.  Usually these parameters are calls to functions defined in the
<b>-script</b> field:</p>
<pre class="verbatim"><ol><li>      $query = new CGI;</li><li>      print header;</li><li>      $JSCRIPT=&lt;&lt;END;</li><li>      // Ask a silly question</li><li>      function riddle_me_this() {</li><li>	 var r = prompt("What walks on four legs in the morning, " +</li><li>		       "two legs in the afternoon, " +</li><li>		       "and three legs in the evening?");</li><li>	 response(r);</li><li>      }</li><li>      // Get a silly answer</li><li>      function response(answer) {</li><li>	 if (answer == "man")</li><li>	    alert("Right you are!");</li><li>	 else</li><li>	    alert("Wrong!  Guess again.");</li><li>      }</li><li>      END</li><li>      print start_html(-title=&gt;'The Riddle of the Sphinx',</li><li>			       -script=&gt;$JSCRIPT);</li></ol></pre><p>Use the <b>-noScript</b> parameter to pass some HTML text that will be displayed on 
browsers that do not have JavaScript (or browsers where JavaScript is turned
off).</p>
<p>The &lt;script&gt; tag, has several attributes including &quot;type&quot; and src.
The latter is particularly interesting, as it allows you to keep the
JavaScript code in a file or CGI script rather than cluttering up each
page with the source.  To use these attributes pass a HASH reference
in the <b>-script</b> parameter containing one or more of -type, -src, or
-code:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;start_html</span><span class="s">(</span>-<span class="w">title</span><span class="cm">=&gt;</span><span class="q">&#39;The Riddle of the Sphinx&#39;</span><span class="cm">,</span></li><li>			 -<span class="w">script</span><span class="cm">=&gt;</span><span class="s">{</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;JAVASCRIPT&#39;</span><span class="cm">,</span></li><li>                                   -<span class="w">src</span><span class="cm">=&gt;</span><span class="q">&#39;/javascript/sphinx.js&#39;</span><span class="s">}</span></li><li>			 <span class="s">)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span>-&gt;<span class="s">(</span>-<span class="w">title</span><span class="cm">=&gt;</span><span class="q">&#39;The Riddle of the Sphinx&#39;</span><span class="cm">,</span></li><li>	       -<span class="w">script</span><span class="cm">=&gt;</span><span class="s">{</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;PERLSCRIPT&#39;</span><span class="cm">,</span></li><li>			 -<span class="w">code</span><span class="cm">=&gt;</span><span class="q">&#39;print &quot;hello world!\n;&quot;&#39;</span><span class="s">}</span></li><li>	       <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>A final feature allows you to incorporate multiple &lt;script&gt; sections into the
header.  Just pass the list of script sections as an array reference.
this allows you to specify different source files for different dialects
of JavaScript.  Example:</p>
<pre class="verbatim"><ol><li>     <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;start_html</span><span class="s">(</span>-<span class="w">title</span><span class="cm">=&gt;</span><span class="q">'The Riddle of the Sphinx'</span><span class="cm">,</span></li><li>                          -<span class="w">script</span><span class="cm">=&gt;</span><span class="s">[</span></li><li>                                    <span class="s">{</span> -<span class="w">type</span> <span class="cm">=&gt;</span> <span class="q">'text/javascript'</span><span class="cm">,</span></li><li>                                      -<span class="w">src</span>      <span class="cm">=&gt;</span> <span class="q">'/javascript/utilities10.js'</span></li><li>                                    <span class="s">}</span><span class="cm">,</span></li><li>                                    <span class="s">{</span> -<span class="w">type</span> <span class="cm">=&gt;</span> <span class="q">'text/javascript'</span><span class="cm">,</span></li><li>                                      -<span class="w">src</span>      <span class="cm">=&gt;</span> <span class="q">'/javascript/utilities11.js'</span></li><li>                                    <span class="s">}</span><span class="cm">,</span></li><li>                                    <span class="s">{</span> -<span class="w">type</span> <span class="cm">=&gt;</span> <span class="q">'text/jscript'</span><span class="cm">,</span></li><li>                                      -<span class="w">src</span>      <span class="cm">=&gt;</span> <span class="q">'/javascript/utilities12.js'</span></li><li>                                    <span class="s">}</span><span class="cm">,</span></li><li>                                    <span class="s">{</span> -<span class="w">type</span> <span class="cm">=&gt;</span> <span class="q">'text/ecmascript'</span><span class="cm">,</span></li><li>                                      -<span class="w">src</span>      <span class="cm">=&gt;</span> <span class="q">'/javascript/utilities219.js'</span></li><li>                                    <span class="s">}</span></li><li>                                 <span class="s">]</span></li><li>                             <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The option &quot;-language&quot; is a synonym for -type, and is supported for
backwad compatibility.</p>
<p>The old-style positional parameters are as follows:</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The title</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The author&#39;s e-mail address (will create a &lt;link rev=&quot;MADE&quot;&gt; tag if present</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>A &#39;true&#39; flag if you want to include a &lt;base&gt; tag in the header.  This
helps resolve relative addresses to absolute ones when the document is moved, 
but makes the document hierarchy non-portable.  Use with care!</p>
</li>
<li><a name="4%2c-5%2c-6..."></a><b>4, 5, 6...</b>
<p>Any other parameters you want to include in the &lt;body&gt; tag.  This is a good
place to put Netscape extensions, such as colors and wallpaper patterns.</p>
</li>
</ul>
<a name="ENDING-THE-HTML-DOCUMENT%3a"></a><h2>ENDING THE HTML DOCUMENT:</h2>
<pre class="verbatim"><ol><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">end_html</span></li></ol></pre><p>This ends an HTML document by printing the &lt;/body&gt;&lt;/html&gt; tags.</p>
<a name="CREATING-A-SELF-REFERENCING-URL-THAT-PRESERVES-STATE-INFORMATION%3a"></a><h2>CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION:</h2>
<pre class="verbatim"><ol><li>    <span class="i">$myself</span> = <span class="w">self_url</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">q(&lt;a href=&quot;$myself&quot;&gt;I&#39;m talking to myself.&lt;/a&gt;)</span><span class="sc">;</span></li></ol></pre><p>self_url() will return a URL, that, when selected, will reinvoke
this script with all its state information intact.  This is most
useful when you want to jump around within the document using
internal anchors but you don&#39;t want to disrupt the current contents
of the form(s).  Something like this will do the trick.</p>
<pre class="verbatim"><ol><li>     <span class="i">$myself</span> = <span class="w">self_url</span><span class="sc">;</span></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;&lt;a href=\&quot;$myself#table1\&quot;&gt;See table 1&lt;/a&gt;&quot;</span><span class="sc">;</span></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;&lt;a href=\&quot;$myself#table2\&quot;&gt;See table 2&lt;/a&gt;&quot;</span><span class="sc">;</span></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;&lt;a href=\&quot;$myself#yourself\&quot;&gt;See for yourself&lt;/a&gt;&quot;</span><span class="sc">;</span></li></ol></pre><p>If you want more control over what&#39;s returned, using the <b>url()</b>
method instead.</p>
<p>You can also retrieve the unprocessed query string with query_string():</p>
<pre class="verbatim"><ol><li>    <span class="i">$the_string</span> = <span class="w">query_string</span><span class="sc">;</span></li></ol></pre><a name="OBTAINING-THE-SCRIPT'S-URL"></a><h2>OBTAINING THE SCRIPT&#39;S URL</h2>
<pre class="verbatim"><ol><li>    <span class="i">$full_url</span>      = <span class="i">url</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$full_url</span>      = <span class="i">url</span><span class="s">(</span>-<span class="w">full</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span>  <span class="c">#alternative syntax</span></li><li>    <span class="i">$relative_url</span>  = <span class="i">url</span><span class="s">(</span>-<span class="w">relative</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$absolute_url</span>  = <span class="i">url</span><span class="s">(</span>-<span class="w">absolute</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$url_with_path</span> = <span class="i">url</span><span class="s">(</span>-<span class="w">path_info</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$url_with_path_and_query</span> = <span class="i">url</span><span class="s">(</span>-<span class="w">path_info</span><span class="cm">=&gt;</span><span class="n">1</span><span class="cm">,</span>-<span class="w">query</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$netloc</span>        = <span class="i">url</span><span class="s">(</span>-<span class="w">base</span> <span class="cm">=&gt;</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><b>url()</b> returns the script&#39;s URL in a variety of formats.  Called
without any arguments, it returns the full form of the URL, including
host name and port number</p>
<pre class="verbatim"><ol><li>    http://your.host.com/path/to/script.cgi</li></ol></pre><p>You can modify this format with the following named arguments:</p>
<ul>
<li><a name="*-absolute*"></a><b><b>-absolute</b></b>
<p>If true, produce an absolute URL, e.g.</p>
<pre class="verbatim"><ol><li>    /path/to/script.cgi</li></ol></pre></li>
<li><a name="*-relative*"></a><b><b>-relative</b></b>
<p>Produce a relative URL.  This is useful if you want to reinvoke your
script with different parameters. For example:</p>
<pre class="verbatim"><ol><li>    <span class="w">script</span>.<span class="w">cgi</span></li></ol></pre></li>
<li><a name="*-full*"></a><b><b>-full</b></b>
<p>Produce the full URL, exactly as if called without any arguments.
This overrides the -relative and -absolute arguments.</p>
</li>
<li><a name="*-path*-(*-path_info*)"></a><b><b>-path</b> (<b>-path_info</b>)</b>
<p>Append the additional path information to the URL.  This can be
combined with <b>-full</b>, <b>-absolute</b> or <b>-relative</b>.  <b>-path_info</b>
is provided as a synonym.</p>
</li>
<li><a name="*-query*-(*-query_string*)"></a><b><b>-query</b> (<b>-query_string</b>)</b>
<p>Append the query string to the URL.  This can be combined with
<b>-full</b>, <b>-absolute</b> or <b>-relative</b>.  <b>-query_string</b> is provided
as a synonym.</p>
</li>
<li><a name="*-base*"></a><b><b>-base</b></b>
<p>Generate just the protocol and net location, as in <a href="http://www.foo.com:8000">http://www.foo.com:8000</a></p>
</li>
<li><a name="*-rewrite*"></a><b><b>-rewrite</b></b>
<p>If Apache&#39;s mod_rewrite is turned on, then the script name and path
info probably won&#39;t match the request that the user sent. Set
-rewrite=&gt;1 (default) to return URLs that match what the user sent
(the original request URI). Set -rewrite=&gt;0 to return URLs that match
the URL after mod_rewrite&#39;s rules have run. Because the additional
path information only makes sense in the context of the rewritten URL,
-rewrite is set to false when you request path info in the URL.</p>
</li>
</ul>
<a name="MIXING-POST-AND-URL-PARAMETERS"></a><h2>MIXING POST AND URL PARAMETERS</h2>
<pre class="verbatim"><ol><li>   <span class="i">$color</span> = <span class="i">url_param</span><span class="s">(</span><span class="q">&#39;color&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>It is possible for a script to receive CGI parameters in the URL as
well as in the fill-out form by creating a form that POSTs to a URL
containing a query string (a &quot;?&quot; mark followed by arguments).  The
<b>param()</b> method will always return the contents of the POSTed
fill-out form, ignoring the URL&#39;s query string.  To retrieve URL
parameters, call the <b>url_param()</b> method.  Use it in the same way as
<b>param()</b>.  The main difference is that it allows you to read the
parameters, but not set them.</p>
<p>Under no circumstances will the contents of the URL query string
interfere with similarly-named CGI parameters in POSTed forms.  If you
try to mix a URL query string with a form submitted with the GET
method, the results will not be what you expect.</p>
<a name="CREATING-STANDARD-HTML-ELEMENTS%3a"></a><h1>CREATING STANDARD HTML ELEMENTS:</h1>
<p>CGI.pm defines general HTML shortcut methods for most, if not all of
the HTML 3 and HTML 4 tags.  HTML shortcuts are named after a single
HTML element and return a fragment of HTML text that you can then
print or manipulate as you like.  Each shortcut returns a fragment of
HTML code that you can append to a string, save to a file, or, most
commonly, print out so that it displays in the browser window.</p>
<p>This example shows how to use the HTML methods:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">$q</span><span class="i">-&gt;blockquote</span><span class="s">(</span></li><li>		     <span class="q">&quot;Many years ago on the island of&quot;</span><span class="cm">,</span></li><li>		     <span class="i">$q</span><span class="i">-&gt;a</span><span class="s">(</span><span class="s">{</span><span class="w">href</span><span class="cm">=&gt;</span><span class="q">&quot;<a href="http://crete.org/">http://crete.org/</a>&quot;</span><span class="s">}</span><span class="cm">,</span><span class="q">&quot;Crete&quot;</span><span class="s">)</span><span class="cm">,</span></li><li>		     <span class="q">&quot;there lived a Minotaur named&quot;</span><span class="cm">,</span></li><li>		     <span class="i">$q</span><span class="i">-&gt;strong</span><span class="s">(</span><span class="q">&quot;Fred.&quot;</span><span class="s">)</span><span class="cm">,</span></li><li>		    <span class="s">)</span><span class="cm">,</span></li><li>       <span class="i">$q</span><span class="i">-&gt;hr</span><span class="sc">;</span></li></ol></pre><p>This results in the following HTML code (extra newlines have been
added for readability):</p>
<pre class="verbatim"><ol><li>   &lt;blockquote&gt;</li><li>   Many years ago on the island of</li><li>   &lt;a href="http://crete.org/"&gt;Crete&lt;/a&gt; there lived</li><li>   a minotaur named &lt;strong&gt;Fred.&lt;/strong&gt; </li><li>   &lt;/blockquote&gt;</li><li>   &lt;hr&gt;</li></ol></pre><p>If you find the syntax for calling the HTML shortcuts awkward, you can
import them into your namespace and dispense with the object syntax
completely (see the next section for more details):</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">&#39;:standard&#39;</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">blockquote</span><span class="s">(</span></li><li>      <span class="q">&quot;Many years ago on the island of&quot;</span><span class="cm">,</span></li><li>      <span class="i">a</span><span class="s">(</span><span class="s">{</span><span class="w">href</span><span class="cm">=&gt;</span><span class="q">&quot;<a href="http://crete.org/">http://crete.org/</a>&quot;</span><span class="s">}</span><span class="cm">,</span><span class="q">&quot;Crete&quot;</span><span class="s">)</span><span class="cm">,</span></li><li>      <span class="q">&quot;there lived a minotaur named&quot;</span><span class="cm">,</span></li><li>      <span class="i">strong</span><span class="s">(</span><span class="q">&quot;Fred.&quot;</span><span class="s">)</span><span class="cm">,</span></li><li>      <span class="s">)</span><span class="cm">,</span></li><li>      <span class="w">hr</span><span class="sc">;</span></li></ol></pre><a name="PROVIDING-ARGUMENTS-TO-HTML-SHORTCUTS"></a><h2>PROVIDING ARGUMENTS TO HTML SHORTCUTS</h2>
<p>The HTML methods will accept zero, one or multiple arguments.  If you
provide no arguments, you get a single tag:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">hr</span><span class="sc">;</span>  	<span class="c">#  &lt;hr&gt;</span></li></ol></pre><p>If you provide one or more string arguments, they are concatenated
together with spaces and placed between opening and closing tags:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">h1</span><span class="s">(</span><span class="q">&quot;Chapter&quot;</span><span class="cm">,</span><span class="q">&quot;1&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># &lt;h1&gt;Chapter 1&lt;/h1&gt;&quot;</span></li></ol></pre><p>If the first argument is a hash reference, then the keys
and values of the hash become the HTML tag&#39;s attributes:</p>
<pre class="verbatim"><ol><li>   print a({-href=&gt;'fred.html',-target=&gt;'_new'},</li><li>      "Open a new frame");</li><li></li><li>	    &lt;a href="fred.html",target="_new"&gt;Open a new frame&lt;/a&gt;</li></ol></pre><p>You may dispense with the dashes in front of the attribute names if
you prefer:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">img</span> <span class="s">{</span><span class="w">src</span><span class="cm">=&gt;</span><span class="q">&#39;fred.gif&#39;</span><span class="cm">,</span><span class="w">align</span><span class="cm">=&gt;</span><span class="q">&#39;LEFT&#39;</span><span class="s">}</span><span class="sc">;</span></li><li></li><li>	   <span class="q">&lt;img align=&quot;LEFT&quot; src=&quot;fred.gif&quot;&gt;</span></li></ol></pre><p>Sometimes an HTML tag attribute has no argument.  For example, ordered
lists can be marked as COMPACT.  The syntax for this is an argument that
that points to an undef string:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">ol</span><span class="s">(</span><span class="s">{</span><span class="w">compact</span><span class="cm">=&gt;</span><a class="l_k" href="functions/undef.html">undef</a><span class="s">}</span><span class="cm">,</span><span class="i">li</span><span class="s">(</span><span class="q">&#39;one&#39;</span><span class="s">)</span><span class="cm">,</span><span class="i">li</span><span class="s">(</span><span class="q">&#39;two&#39;</span><span class="s">)</span><span class="cm">,</span><span class="i">li</span><span class="s">(</span><span class="q">&#39;three&#39;</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Prior to CGI.pm version 2.41, providing an empty (&#39;&#39;) string as an
attribute argument was the same as providing undef.  However, this has
changed in order to accommodate those who want to create tags of the form 
&lt;img alt=&quot;&quot;&gt;.  The difference is shown in these two pieces of code:</p>
<pre class="verbatim"><ol><li>   <span class="w">CODE</span>                   <span class="w">RESULT</span></li><li>   <span class="i">img</span><span class="s">(</span><span class="s">{</span><span class="w">alt</span><span class="cm">=&gt;</span><a class="l_k" href="functions/undef.html">undef</a><span class="s">}</span><span class="s">)</span>      &lt;<span class="w">img</span> <span class="w">alt</span>&gt;</li><li>   <span class="i">img</span><span class="s">(</span><span class="s">{</span><span class="w">alt</span><span class="cm">=&gt;</span><span class="q">&#39;&#39;</span><span class="s">}</span><span class="s">)</span>         &lt;<span class="w">img</span> <span class="w">alt</span>=<span class="q">&quot;&quot;</span>&gt;</li></ol></pre><a name="THE-DISTRIBUTIVE-PROPERTY-OF-HTML-SHORTCUTS"></a><h2>THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS</h2>
<p>One of the cool features of the HTML shortcuts is that they are
distributive.  If you give them an argument consisting of a
<b>reference</b> to a list, the tag will be distributed across each
element of the list.  For example, here&#39;s one way to make an ordered
list:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">ul</span><span class="s">(</span></li><li>             <span class="i">li</span><span class="s">(</span><span class="s">{</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;disc&#39;</span><span class="s">}</span><span class="cm">,</span><span class="s">[</span><span class="q">&#39;Sneezy&#39;</span><span class="cm">,</span><span class="q">&#39;Doc&#39;</span><span class="cm">,</span><span class="q">&#39;Sleepy&#39;</span><span class="cm">,</span><span class="q">&#39;Happy&#39;</span><span class="s">]</span><span class="s">)</span></li><li>           <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This example will result in HTML output that looks like this:</p>
<pre class="verbatim"><ol><li>   &lt;ul&gt;</li><li>     &lt;li type="disc"&gt;Sneezy&lt;/li&gt;</li><li>     &lt;li type="disc"&gt;Doc&lt;/li&gt;</li><li>     &lt;li type="disc"&gt;Sleepy&lt;/li&gt;</li><li>     &lt;li type="disc"&gt;Happy&lt;/li&gt;</li><li>   &lt;/ul&gt;</li></ol></pre><p>This is extremely useful for creating tables.  For example:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">table</span><span class="s">(</span><span class="s">{</span>-<span class="w">border</span><span class="cm">=&gt;</span><a class="l_k" href="functions/undef.html">undef</a><span class="s">}</span><span class="cm">,</span></li><li>           <span class="i">caption</span><span class="s">(</span><span class="q">&#39;When Should You Eat Your Vegetables?&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>           <span class="i">Tr</span><span class="s">(</span><span class="s">{</span>-<span class="w">align</span><span class="cm">=&gt;</span><span class="w">CENTER</span><span class="cm">,</span>-<span class="w">valign</span><span class="cm">=&gt;</span><span class="w">TOP</span><span class="s">}</span><span class="cm">,</span></li><li>           <span class="s">[</span></li><li>              <span class="i">th</span><span class="s">(</span><span class="s">[</span><span class="q">&#39;Vegetable&#39;</span><span class="cm">,</span> <span class="q">&#39;Breakfast&#39;</span><span class="cm">,</span><span class="q">&#39;Lunch&#39;</span><span class="cm">,</span><span class="q">&#39;Dinner&#39;</span><span class="s">]</span><span class="s">)</span><span class="cm">,</span></li><li>              <span class="i">td</span><span class="s">(</span><span class="s">[</span><span class="q">&#39;Tomatoes&#39;</span> <span class="cm">,</span> <span class="q">&#39;no&#39;</span><span class="cm">,</span> <span class="q">&#39;yes&#39;</span><span class="cm">,</span> <span class="q">&#39;yes&#39;</span><span class="s">]</span><span class="s">)</span><span class="cm">,</span></li><li>              <span class="i">td</span><span class="s">(</span><span class="s">[</span><span class="q">&#39;Broccoli&#39;</span> <span class="cm">,</span> <span class="q">&#39;no&#39;</span><span class="cm">,</span> <span class="q">&#39;no&#39;</span><span class="cm">,</span>  <span class="q">&#39;yes&#39;</span><span class="s">]</span><span class="s">)</span><span class="cm">,</span></li><li>              <span class="i">td</span><span class="s">(</span><span class="s">[</span><span class="q">&#39;Onions&#39;</span>   <span class="cm">,</span> <span class="q">&#39;yes&#39;</span><span class="cm">,</span><span class="q">&#39;yes&#39;</span><span class="cm">,</span> <span class="q">&#39;yes&#39;</span><span class="s">]</span><span class="s">)</span></li><li>           <span class="s">]</span></li><li>           <span class="s">)</span></li><li>        <span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="HTML-SHORTCUTS-AND-LIST-INTERPOLATION"></a><h2>HTML SHORTCUTS AND LIST INTERPOLATION</h2>
<p>Consider this bit of code:</p>
<pre class="verbatim"><ol><li>   print blockquote(em('Hi'),'mom!'));</li></ol></pre><p>It will ordinarily return the string that you probably expect, namely:</p>
<pre class="verbatim"><ol><li>   &lt;blockquote&gt;&lt;em&gt;Hi&lt;/em&gt; mom!&lt;/blockquote&gt;</li></ol></pre><p>Note the space between the element &quot;Hi&quot; and the element &quot;mom!&quot;.
CGI.pm puts the extra space there using array interpolation, which is
controlled by the magic $&quot; variable.  Sometimes this extra space is
not what you want, for example, when you are trying to align a series
of images.  In this case, you can simply change the value of $&quot; to an
empty string.</p>
<pre class="verbatim"><ol><li>   {</li><li>      local($") = '';</li><li>      print blockquote(em('Hi'),'mom!'));</li><li>    }</li></ol></pre><p>I suggest you put the code in a block as shown here.  Otherwise the
change to $&quot; will affect all subsequent code until you explicitly
reset it.</p>
<a name="NON-STANDARD-HTML-SHORTCUTS"></a><h2>NON-STANDARD HTML SHORTCUTS</h2>
<p>A few HTML tags don&#39;t follow the standard pattern for various
reasons.</p>
<p><b>comment()</b> generates an HTML comment (&lt;!-- comment --&gt;).  Call it
like</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">comment</span><span class="s">(</span><span class="q">&#39;here is my comment&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Because of conflicts with built-in Perl functions, the following functions
begin with initial caps:</p>
<pre class="verbatim"><ol><li>    <span class="w">Select</span></li><li>    <span class="w">Tr</span></li><li>    <span class="w">Link</span></li><li>    <span class="w">Delete</span></li><li>    <span class="w">Accept</span></li><li>    <span class="w">Sub</span></li></ol></pre><p>In addition, start_html(), end_html(), start_form(), end_form(),
start_multipart_form() and all the fill-out form tags are special.
See their respective sections.</p>
<a name="AUTOESCAPING-HTML"></a><h2>AUTOESCAPING HTML</h2>
<p>By default, all HTML that is emitted by the form-generating functions
is passed through a function called escapeHTML():</p>
<ul>
<li><a name="%24escaped_string-%3d-escapeHTML(%22unescaped-string%22)%3b"></a><b>$escaped_string = escapeHTML(&quot;unescaped string&quot;);</b>
<p>Escape HTML formatting characters in a string.</p>
</li>
</ul>
<p>Provided that you have specified a character set of ISO-8859-1 (the
default), the standard HTML escaping rules will be used.  The &quot;&lt;&quot;
character becomes &quot;&amp;lt;&quot;, &quot;&gt;&quot; becomes &quot;&amp;gt;&quot;, &quot;&amp;&quot; becomes &quot;&amp;amp;&quot;, and
the quote character becomes &quot;&amp;quot;&quot;.  In addition, the hexadecimal
0x8b and 0x9b characters, which some browsers incorrectly interpret
as the left and right angle-bracket characters, are replaced by their
numeric character entities (&quot;&amp;#8249&quot; and &quot;&amp;#8250;&quot;).  If you manually change
the charset, either by calling the charset() method explicitly or by
passing a -charset argument to header(), then <b>all</b> characters will
be replaced by their numeric entities, since CGI.pm has no lookup
table for all the possible encodings.</p>
<p>The automatic escaping does not apply to other shortcuts, such as
h1().  You should call escapeHTML() yourself on untrusted data in
order to protect your pages against nasty tricks that people may enter
into guestbooks, etc..  To change the character set, use charset().
To turn autoescaping off completely, use autoEscape(0):</p>
<ul>
<li><a name="%24charset-%3d-charset(%5b%24charset%5d)%3b"></a><b>$charset = charset([$charset]);</b>
<p>Get or set the current character set.</p>
</li>
<li><a name="%24flag-%3d-autoEscape(%5b%24flag%5d)%3b"></a><b>$flag = autoEscape([$flag]);</b>
<p>Get or set the value of the autoescape flag.</p>
</li>
</ul>
<a name="PRETTY-PRINTING-HTML"></a><h2>PRETTY-PRINTING HTML</h2>
<p>By default, all the HTML produced by these functions comes out as one
long line without carriage returns or indentation. This is yuck, but
it does reduce the size of the documents by 10-20%.  To get
pretty-printed output, please use <a href="CGI/Pretty.html">CGI::Pretty</a>, a subclass
contributed by Brian Paulsen.</p>
<a name="CREATING-FILL-OUT-FORMS%3a"></a><h1>CREATING FILL-OUT FORMS:</h1>
<p><i>General note</i>  The various form-creating methods all return strings
to the caller, containing the tag or tags that will create the requested
form element.  You are responsible for actually printing out these strings.
It&#39;s set up this way so that you can place formatting tags
around the form elements.</p>
<p><i>Another note</i> The default values that you specify for the forms are only
used the <b>first</b> time the script is invoked (when there is no query
string).  On subsequent invocations of the script (when there is a query
string), the former values are used even if they are blank.</p>
<p>If you want to change the value of a field from its previous value, you have two
choices:</p>
<p>(1) call the param() method to set it.</p>
<p>(2) use the -override (alias -force) parameter (a new feature in version 2.15).
This forces the default value to be used, regardless of the previous value:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">textfield</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;field_name&#39;</span><span class="cm">,</span></li><li>			   -<span class="w">default</span><span class="cm">=&gt;</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span></li><li>			   -<span class="w">override</span><span class="cm">=&gt;</span><span class="n">1</span><span class="cm">,</span></li><li>			   -<span class="w">size</span><span class="cm">=&gt;</span><span class="n">50</span><span class="cm">,</span></li><li>			   -<span class="w">maxlength</span><span class="cm">=&gt;</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><i>Yet another note</i> By default, the text and labels of form elements are
escaped according to HTML rules.  This means that you can safely use
&quot;&lt;CLICK ME&gt;&quot; as the label for a button.  However, it also interferes with
your ability to incorporate special HTML character sequences, such as &amp;Aacute;,
into your fields.  If you wish to turn off automatic escaping, call the
autoEscape() method with a false value immediately after creating the CGI object:</p>
<pre class="verbatim"><ol><li>   <span class="i">$query</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>   <span class="i">autoEscape</span><span class="s">(</span><a class="l_k" href="functions/undef.html">undef</a><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><i>A Lurking Trap!</i> Some of the form-element generating methods return
multiple tags.  In a scalar context, the tags will be concatenated
together with spaces, or whatever is the current value of the $&quot;
global.  In a list context, the methods will return a list of
elements, allowing you to modify them if you wish.  Usually you will
not notice this behavior, but beware of this:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/printf.html">printf</a><span class="s">(</span><span class="q">&quot;%s\n&quot;</span><span class="cm">,</span><span class="i">end_form</span><span class="s">(</span><span class="s">)</span><span class="s">)</span></li></ol></pre><p>end_form() produces several tags, and only the first of them will be
printed because the format only expects one value.</p>
<p>&lt;p&gt;</p>
<a name="CREATING-AN-ISINDEX-TAG"></a><h2>CREATING AN ISINDEX TAG</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">isindex</span><span class="s">(</span>-<span class="w">action</span><span class="cm">=&gt;</span><span class="i">$action</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	 -or-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">isindex</span><span class="s">(</span><span class="i">$action</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Prints out an &lt;isindex&gt; tag.  Not very exciting.  The parameter
-action specifies the URL of the script to process the query.  The
default is to process the query with the current script.</p>
<a name="STARTING-AND-ENDING-A-FORM"></a><h2>STARTING AND ENDING A FORM</h2>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">start_form</span><span class="s">(</span>-<span class="w">method</span><span class="cm">=&gt;</span><span class="i">$method</span><span class="cm">,</span></li><li>		    -<span class="w">action</span><span class="cm">=&gt;</span><span class="i">$action</span><span class="cm">,</span></li><li>		    -<span class="w">enctype</span><span class="cm">=&gt;</span><span class="i">$encoding</span><span class="s">)</span><span class="sc">;</span></li><li>      <span class="q">&lt;... various form stuff ...&gt;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">endform</span><span class="sc">;</span></li><li></li><li>	-or-</li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">start_form</span><span class="s">(</span><span class="i">$method</span><span class="cm">,</span><span class="i">$action</span><span class="cm">,</span><span class="i">$encoding</span><span class="s">)</span><span class="sc">;</span></li><li>      <span class="q">&lt;... various form stuff ...&gt;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">endform</span><span class="sc">;</span></li></ol></pre><p>start_form() will return a &lt;form&gt; tag with the optional method,
action and form encoding that you specify.  The defaults are:</p>
<pre class="verbatim"><ol><li>    method: POST</li><li>    action: this script</li><li>    enctype: application/x-www-form-urlencoded</li></ol></pre><p>endform() returns the closing &lt;/form&gt; tag.</p>
<p>Start_form()&#39;s enctype argument tells the browser how to package the various
fields of the form before sending the form to the server.  Two
values are possible:</p>
<p><b>Note:</b> This method was previously named startform(), and startform()
is still recognized as an alias.</p>
<ul>
<li><a name="*application%2fx-www-form-urlencoded*"></a><b><b>application/x-www-form-urlencoded</b></b>
<p>This is the older type of encoding used by all browsers prior to
Netscape 2.0.  It is compatible with many CGI scripts and is
suitable for short fields containing text data.  For your
convenience, CGI.pm stores the name of this encoding
type in <b>&amp;CGI::URL_ENCODED</b>.</p>
</li>
<li><a name="*multipart%2fform-data*"></a><b><b>multipart/form-data</b></b>
<p>This is the newer type of encoding introduced by Netscape 2.0.
It is suitable for forms that contain very large fields or that
are intended for transferring binary data.  Most importantly,
it enables the &quot;file upload&quot; feature of Netscape 2.0 forms.  For
your convenience, CGI.pm stores the name of this encoding type
in <b>&amp;CGI::MULTIPART</b></p>
<p>Forms that use this type of encoding are not easily interpreted
by CGI scripts unless they use CGI.pm or another library designed
to handle them.</p>
<p>If XHTML is activated (the default), then forms will be automatically
created using this type of encoding.</p>
</li>
</ul>
<p>For compatibility, the start_form() method uses the older form of
encoding by default.  If you want to use the newer form of encoding
by default, you can call <b>start_multipart_form()</b> instead of
<b>start_form()</b>.</p>
<p>JAVASCRIPTING: The <b>-name</b> and <b>-onSubmit</b> parameters are provided
for use with JavaScript.  The -name parameter gives the
form a name so that it can be identified and manipulated by
JavaScript functions.  -onSubmit should point to a JavaScript
function that will be executed just before the form is submitted to your
server.  You can use this opportunity to check the contents of the form 
for consistency and completeness.  If you find something wrong, you
can put up an alert box or maybe fix things up yourself.  You can 
abort the submission by returning false from this function.</p>
<p>Usually the bulk of JavaScript functions are defined in a &lt;script&gt;
block in the HTML header and -onSubmit points to one of these function
call.  See start_html() for details.</p>
<a name="FORM-ELEMENTS"></a><h2>FORM ELEMENTS</h2>
<p>After starting a form, you will typically create one or more
textfields, popup menus, radio groups and other form elements.  Each
of these elements takes a standard set of named arguments.  Some
elements also have optional arguments.  The standard arguments are as
follows:</p>
<ul>
<li><a name="*-name*"></a><b><b>-name</b></b>
<p>The name of the field. After submission this name can be used to
retrieve the field&#39;s value using the param() method.</p>
</li>
<li><a name="*-value*%2c-*-values*"></a><b><b>-value</b>, <b>-values</b></b>
<p>The initial value of the field which will be returned to the script
after form submission.  Some form elements, such as text fields, take
a single scalar -value argument. Others, such as popup menus, take a
reference to an array of values. The two arguments are synonyms.</p>
</li>
<li><a name="*-tabindex*"></a><b><b>-tabindex</b></b>
<p>A numeric value that sets the order in which the form element receives
focus when the user presses the tab key. Elements with lower values
receive focus first.</p>
</li>
<li><a name="*-id*"></a><b><b>-id</b></b>
<p>A string identifier that can be used to identify this element to
JavaScript and DHTML.</p>
</li>
<li><a name="*-override*"></a><b><b>-override</b></b>
<p>A boolean, which, if true, forces the element to take on the value
specified by <b>-value</b>, overriding the sticky behavior described
earlier for the <b>-no_sticky</b> pragma.</p>
</li>
<li><a name="*-onChange*%2c-*-onFocus*%2c-*-onBlur*%2c-*-onMouseOver*%2c-*-onMouseOut*%2c-*-onSelect*"></a><b><b>-onChange</b>, <b>-onFocus</b>, <b>-onBlur</b>, <b>-onMouseOver</b>, <b>-onMouseOut</b>, <b>-onSelect</b></b>
<p>These are used to assign JavaScript event handlers. See the
JavaScripting section for more details.</p>
</li>
</ul>
<p>Other common arguments are described in the next section. In addition
to these, all attributes described in the HTML specifications are
supported.</p>
<a name="CREATING-A-TEXT-FIELD"></a><h2>CREATING A TEXT FIELD</h2>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">textfield</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;field_name&#39;</span><span class="cm">,</span></li><li>		    -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span></li><li>		    -<span class="w">size</span><span class="cm">=&gt;</span><span class="n">50</span><span class="cm">,</span></li><li>		    -<span class="w">maxlength</span><span class="cm">=&gt;</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li><li>	-or-</li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">textfield</span><span class="s">(</span><span class="q">&#39;field_name&#39;</span><span class="cm">,</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span><span class="n">50</span><span class="cm">,</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>textfield() will return a text input field.</p>
<ul>
<li><a name="*Parameters*"></a><b><b>Parameters</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first parameter is the required name for the field (-name).</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The optional second parameter is the default starting value for the field
contents (-value, formerly known as -default).</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional third parameter is the size of the field in
      characters (-size).</p>
</li>
<li><a name="4."></a><b>4.</b>
<p>The optional fourth parameter is the maximum number of characters the
      field will accept (-maxlength).</p>
</li>
</ul>
<p>As with all these methods, the field will be initialized with its 
previous contents from earlier invocations of the script.
When the form is processed, the value of the text field can be
retrieved with:</p>
<pre class="verbatim"><ol><li>       <span class="i">$value</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you want to reset it from its initial value after the script has been
called once, you can do so like this:</p>
<pre class="verbatim"><ol><li>       <span class="i">param</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span><span class="q">&quot;I&#39;m taking over this value!&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-BIG-TEXT-FIELD"></a><h2>CREATING A BIG TEXT FIELD</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">textarea</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span></li><li>			  -<span class="w">default</span><span class="cm">=&gt;</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span></li><li>			  -<span class="w">rows</span><span class="cm">=&gt;</span><span class="n">10</span><span class="cm">,</span></li><li>			  -<span class="w">columns</span><span class="cm">=&gt;</span><span class="n">50</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">textarea</span><span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="cm">,</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span><span class="n">10</span><span class="cm">,</span><span class="n">50</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>textarea() is just like textfield, but it allows you to specify
rows and columns for a multiline text entry box.  You can provide
a starting value for the field, which can be long and contain
multiple lines.</p>
<a name="CREATING-A-PASSWORD-FIELD"></a><h2>CREATING A PASSWORD FIELD</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">password_field</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;secret&#39;</span><span class="cm">,</span></li><li>				-<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span></li><li>				-<span class="w">size</span><span class="cm">=&gt;</span><span class="n">50</span><span class="cm">,</span></li><li>				-<span class="w">maxlength</span><span class="cm">=&gt;</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li><li>	-or-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">password_field</span><span class="s">(</span><span class="q">&#39;secret&#39;</span><span class="cm">,</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span><span class="n">50</span><span class="cm">,</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>password_field() is identical to textfield(), except that its contents 
will be starred out on the web page.</p>
<a name="CREATING-A-FILE-UPLOAD-FIELD"></a><h2>CREATING A FILE UPLOAD FIELD</h2>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">filefield</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;uploaded_file&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">default</span><span class="cm">=&gt;</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">size</span><span class="cm">=&gt;</span><span class="n">50</span><span class="cm">,</span></li><li>			    -<span class="w">maxlength</span><span class="cm">=&gt;</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li><li>	-or-</li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">filefield</span><span class="s">(</span><span class="q">&#39;uploaded_file&#39;</span><span class="cm">,</span><span class="q">&#39;starting value&#39;</span><span class="cm">,</span><span class="n">50</span><span class="cm">,</span><span class="n">80</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>filefield() will return a file upload field for Netscape 2.0 browsers.
In order to take full advantage of this <i>you must use the new 
multipart encoding scheme</i> for the form.  You can do this either
by calling <b>start_form()</b> with an encoding type of <b>&amp;CGI::MULTIPART</b>,
or by calling the new method <b>start_multipart_form()</b> instead of
vanilla <b>start_form()</b>.</p>
<ul>
<li><a name="*Parameters*"></a><b><b>Parameters</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first parameter is the required name for the field (-name).</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The optional second parameter is the starting value for the field contents
to be used as the default file name (-default).</p>
<p>For security reasons, browsers don&#39;t pay any attention to this field,
and so the starting value will always be blank.  Worse, the field
loses its &quot;sticky&quot; behavior and forgets its previous contents.  The
starting value field is called for in the HTML specification, however,
and possibly some browser will eventually provide support for it.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional third parameter is the size of the field in
characters (-size).</p>
</li>
<li><a name="4."></a><b>4.</b>
<p>The optional fourth parameter is the maximum number of characters the
field will accept (-maxlength).</p>
</li>
</ul>
<p>When the form is processed, you can retrieve the entered filename
by calling param():</p>
<pre class="verbatim"><ol><li>       <span class="i">$filename</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;uploaded_file&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Different browsers will return slightly different things for the
name.  Some browsers return the filename only.  Others return the full
path to the file, using the path conventions of the user&#39;s machine.
Regardless, the name returned is always the name of the file on the
<i>user&#39;s</i> machine, and is unrelated to the name of the temporary file
that CGI.pm creates during upload spooling (see below).</p>
<p>The filename returned is also a file handle.  You can read the contents
of the file using standard Perl file reading calls:</p>
<pre class="verbatim"><ol><li>	<span class="c"># Read a text file and print it out</span></li><li>	while <span class="s">(</span><span class="q">&lt;$filename&gt;</span><span class="s">)</span> <span class="s">{</span></li><li>	   <a class="l_k" href="functions/print.html">print</a><span class="sc">;</span></li><li>	<span class="s">}</span></li><li></li><li>	<span class="c"># Copy a binary file to somewhere safe</span></li><li>	<a class="l_k" href="functions/open.html">open</a> <span class="s">(</span><span class="w">OUTFILE</span><span class="cm">,</span><span class="q">&quot;&gt;&gt;/usr/local/web/users/feedback&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>	while <span class="s">(</span><span class="i">$bytesread</span>=<a class="l_k" href="functions/read.html">read</a><span class="s">(</span><span class="i">$filename</span><span class="cm">,</span><span class="i">$buffer</span><span class="cm">,</span><span class="n">1024</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>	   <a class="l_k" href="functions/print.html">print</a> <span class="i">OUTFILE</span> <span class="i">$buffer</span><span class="sc">;</span></li><li>	<span class="s">}</span></li></ol></pre><p>However, there are problems with the dual nature of the upload fields.
If you <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span></code>
, then Perl will complain when you try to use a
string as a filehandle.  You can get around this by placing the file
reading code in a block containing the <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">strict</span></code>
 pragma.  More
seriously, it is possible for the remote user to type garbage into the
upload field, in which case what you get from param() is not a
filehandle at all, but a string.</p>
<p>To be safe, use the <i>upload()</i> function (new in version 2.47).  When
called with the name of an upload field, <i>upload()</i> returns a
filehandle-like object, or undef if the parameter is not a valid
filehandle.</p>
<pre class="verbatim"><ol><li>     <span class="i">$fh</span> = <span class="i">upload</span><span class="s">(</span><span class="q">&#39;uploaded_file&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>     while <span class="s">(</span><span class="q">&lt;$fh&gt;</span><span class="s">)</span> <span class="s">{</span></li><li>	   <a class="l_k" href="functions/print.html">print</a><span class="sc">;</span></li><li>     <span class="s">}</span></li></ol></pre><p>In a list context, upload() will return an array of filehandles.
This makes it possible to create forms that use the same name for
multiple upload fields.</p>
<p>This is the recommended idiom.</p>
<p>The lightweight filehandle returned by CGI.pm is not compatible with
IO::Handle; for example, it does not have read() or getline()
functions, but instead must be manipulated using read($fh) or
&lt;$fh&gt;. To get a compatible IO::Handle object, call the handle&#39;s
handle() method:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$real_io_handle</span> = <span class="i">upload</span><span class="s">(</span><span class="q">'uploaded_file'</span><span class="s">)</span><span class="i">-&gt;handle</span><span class="sc">;</span></li></ol></pre><p>When a file is uploaded the browser usually sends along some
information along with it in the format of headers.  The information
usually includes the MIME content type.  Future browsers may send
other information as well (such as modification date and size). To
retrieve this information, call uploadInfo().  It returns a reference to
a hash containing all the document headers.</p>
<pre class="verbatim"><ol><li>       <span class="i">$filename</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;uploaded_file&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>       <span class="i">$type</span> = <span class="i">uploadInfo</span><span class="s">(</span><span class="i">$filename</span><span class="s">)</span>-&gt;{<span class="q">&#39;Content-Type&#39;</span>}<span class="sc">;</span></li><li>       unless <span class="s">(</span><span class="i">$type</span> eq <span class="q">&#39;text/html&#39;</span><span class="s">)</span> <span class="s">{</span></li><li>	  <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;HTML FILES ONLY!&quot;</span><span class="sc">;</span></li><li>       <span class="s">}</span></li></ol></pre><p>If you are using a machine that recognizes &quot;text&quot; and &quot;binary&quot; data
modes, be sure to understand when and how to use them (see the Camel book).  
Otherwise you may find that binary files are corrupted during file
uploads.</p>
<p>There are occasionally problems involving parsing the uploaded file.
This usually happens when the user presses &quot;Stop&quot; before the upload is
finished.  In this case, CGI.pm will return undef for the name of the
uploaded file and set <i>cgi_error()</i> to the string &quot;400 Bad request
(malformed multipart POST)&quot;.  This error message is designed so that
you can incorporate it into a status code to be sent to the browser.
Example:</p>
<pre class="verbatim"><ol><li>   <span class="i">$file</span> = <span class="i">upload</span><span class="s">(</span><span class="q">&#39;uploaded_file&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   if <span class="s">(</span>!<span class="i">$file</span> &amp;&amp; <span class="w">cgi_error</span><span class="s">)</span> <span class="s">{</span></li><li>      <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">status</span><span class="cm">=&gt;</span><span class="w">cgi_error</span><span class="s">)</span><span class="sc">;</span></li><li>      <a class="l_k" href="functions/exit.html">exit</a> <span class="n">0</span><span class="sc">;</span></li><li>   <span class="s">}</span></li></ol></pre><p>You are free to create a custom HTML page to complain about the error,
if you wish.</p>
<p>You can set up a callback that will be called whenever a file upload
is being read during the form processing. This is much like the
UPLOAD_HOOK facility available in Apache::Request, with the exception
that the first argument to the callback is an Apache::Upload object,
here it&#39;s the remote filename.</p>
<pre class="verbatim"><ol><li> <span class="i">$q</span> = <span class="w">CGI</span><span class="w">-&gt;new</span><span class="s">(</span>\<span class="i">&amp;hook</span> [<span class="cm">,</span><span class="i">$data</span> [<span class="cm">,</span><span class="i">$use_tempfile</span>]]<span class="s">)</span><span class="sc">;</span></li><li></li><li><a name="hook"></a> sub <span class="m">hook</span></li><li> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$filename</span><span class="cm">,</span> <span class="i">$buffer</span><span class="cm">,</span> <span class="i">$bytes_read</span><span class="cm">,</span> <span class="i">$data</span><span class="s">)</span> = <span class="i">@_</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/print.html">print</a>  <span class="q">&quot;Read $bytes_read bytes of $filename\n&quot;</span><span class="sc">;</span>         </li><li> <span class="s">}</span></li></ol></pre><p>The $data field is optional; it lets you pass configuration
information (e.g. a database handle) to your hook callback.</p>
<p>The $use_tempfile field is a flag that lets you turn on and off
CGI.pm&#39;s use of a temporary disk-based file during file upload. If you
set this to a FALSE value (default true) then param(&#39;uploaded_file&#39;)
will no longer work, and the only way to get at the uploaded data is
via the hook you provide.</p>
<p>If using the function-oriented interface, call the CGI::upload_hook()
method before calling param() or any other CGI functions:</p>
<pre class="verbatim"><ol><li>  <span class="i">CGI::upload_hook</span><span class="s">(</span>\<span class="i">&amp;hook</span> [<span class="cm">,</span><span class="i">$data</span> [<span class="cm">,</span><span class="i">$use_tempfile</span>]]<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This method is not exported by default.  You will have to import it
explicitly if you wish to use it without the CGI:: prefix.</p>
<p>If you are using CGI.pm on a Windows platform and find that binary
files get slightly larger when uploaded but that text files remain the
same, then you have forgotten to activate binary mode on the output
filehandle.  Be sure to call binmode() on any handle that you create
to write the uploaded file to disk.</p>
<p>JAVASCRIPTING: The <b>-onChange</b>, <b>-onFocus</b>, <b>-onBlur</b>,
<b>-onMouseOver</b>, <b>-onMouseOut</b> and <b>-onSelect</b> parameters are
recognized.  See textfield() for details.</p>
<a name="CREATING-A-POPUP-MENU"></a><h2>CREATING A POPUP MENU</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">popup_menu</span><span class="s">(</span><span class="q">&#39;menu_name&#39;</span><span class="cm">,</span></li><li>			    <span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>			    <span class="q">&#39;meenie&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>      -or-</li><li></li><li>   <span class="i">%labels</span> = <span class="s">(</span><span class="q">&#39;eenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;your first choice&#39;</span><span class="cm">,</span></li><li>	      <span class="q">&#39;meenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;your second choice&#39;</span><span class="cm">,</span></li><li>	      <span class="q">&#39;minie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;your third choice&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="i">%attributes</span> = <span class="s">(</span><span class="q">&#39;eenie&#39;</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;class&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;class of first choice&#39;</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">popup_menu</span><span class="s">(</span><span class="q">&#39;menu_name&#39;</span><span class="cm">,</span></li><li>			    <span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>          <span class="q">&#39;meenie&#39;</span><span class="cm">,</span>\<span class="i">%labels</span><span class="cm">,</span>\<span class="i">%attributes</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or <span class="s">(</span><span class="w">named</span> <span class="w">parameter</span> <span class="w">style</span><span class="s">)</span>-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">popup_menu</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;menu_name&#39;</span><span class="cm">,</span></li><li>			    -<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>			    -<span class="w">default</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>          -<span class="w">labels</span><span class="cm">=&gt;</span>\<span class="i">%labels</span><span class="cm">,</span></li><li>          -<span class="w">attributes</span><span class="cm">=&gt;</span>\<span class="i">%attributes</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>popup_menu() creates a menu.</p>
<ol>
<li>
<p>The required first argument is the menu&#39;s name (-name).</p>
</li>
<li>
<p>The required second argument (-values) is an array <b>reference</b>
containing the list of menu items in the menu.  You can pass the
method an anonymous array, as shown in the example, or a reference to
a named array, such as &quot;\@foo&quot;.</p>
</li>
<li>
<p>The optional third parameter (-default) is the name of the default
menu choice.  If not specified, the first item will be the default.
The values of the previous choice will be maintained across
queries. Pass an array reference to select multiple defaults.</p>
</li>
<li>
<p>The optional fourth parameter (-labels) is provided for people who
want to use different values for the user-visible label inside the
popup menu and the value returned to your script.  It&#39;s a pointer to an
hash relating menu values to user-visible labels.  If you
leave this parameter blank, the menu values will be displayed by
default.  (You can also leave a label undefined if you want to).</p>
</li>
<li>
<p>The optional fifth parameter (-attributes) is provided to assign
any of the common HTML attributes to an individual menu item. It&#39;s
a pointer to a hash relating menu values to another
hash with the attribute&#39;s name as the key and the
attribute&#39;s value as the value.</p>
</li>
</ol>
<p>When the form is processed, the selected value of the popup menu can
be retrieved using:</p>
<pre class="verbatim"><ol><li>      <span class="i">$popup_menu_value</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;menu_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-AN-OPTION-GROUP"></a><h2>CREATING AN OPTION GROUP</h2>
<p>Named parameter style</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">popup_menu</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;menu_name&#39;</span><span class="cm">,</span></li><li>                  -<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">qw/eenie meenie minie/</span><span class="cm">,</span></li><li>                            <span class="i">optgroup</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;optgroup_name&#39;</span><span class="cm">,</span></li><li>                                             -<span class="w">values</span> <span class="cm">=&gt;</span> <span class="s">[</span><span class="q">&#39;moe&#39;</span><span class="cm">,</span><span class="q">&#39;catch&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>                                             -<span class="w">attributes</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;catch&#39;</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;class&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;red&#39;</span><span class="s">}</span><span class="s">}</span><span class="s">)</span><span class="s">]</span><span class="cm">,</span></li><li>                  -<span class="w">labels</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;eenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;one&#39;</span><span class="cm">,</span></li><li>                            <span class="q">&#39;meenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;two&#39;</span><span class="cm">,</span></li><li>                            <span class="q">&#39;minie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;three&#39;</span><span class="s">}</span><span class="cm">,</span></li><li>                  -<span class="w">default</span><span class="cm">=&gt;</span><span class="q">&#39;meenie&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>  <span class="w">Old</span> <span class="w">style</span></li><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">popup_menu</span><span class="s">(</span><span class="q">&#39;menu_name&#39;</span><span class="cm">,</span></li><li>                  <span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span></li><li>                   <span class="i">optgroup</span><span class="s">(</span><span class="q">&#39;optgroup_name&#39;</span><span class="cm">,</span> <span class="s">[</span><span class="q">&#39;moe&#39;</span><span class="cm">,</span> <span class="q">&#39;catch&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>                                   <span class="s">{</span><span class="q">&#39;catch&#39;</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;class&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;red&#39;</span><span class="s">}</span><span class="s">}</span><span class="s">)</span><span class="s">]</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span></li><li>                  <span class="s">{</span><span class="q">&#39;eenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;one&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;two&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;three&#39;</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>optgroup() creates an option group within a popup menu.</p>
<ol>
<li>
<p>The required first argument (<b>-name</b>) is the label attribute of the
optgroup and is <b>not</b> inserted in the parameter list of the query.</p>
</li>
<li>
<p>The required second argument (<b>-values</b>)  is an array reference
containing the list of menu items in the menu.  You can pass the
method an anonymous array, as shown in the example, or a reference
to a named array, such as \@foo.  If you pass a HASH reference,
the keys will be used for the menu values, and the values will be
used for the menu labels (see -labels below).</p>
</li>
<li>
<p>The optional third parameter (<b>-labels</b>) allows you to pass a reference
to a hash containing user-visible labels for one or more
of the menu items.  You can use this when you want the user to see one
menu string, but have the browser return your program a different one.
If you don&#39;t specify this, the value string will be used instead
(&quot;eenie&quot;, &quot;meenie&quot; and &quot;minie&quot; in this example).  This is equivalent
to using a hash reference for the -values parameter.</p>
</li>
<li>
<p>An optional fourth parameter (<b>-labeled</b>) can be set to a true value
and indicates that the values should be used as the label attribute
for each option element within the optgroup.</p>
</li>
<li>
<p>An optional fifth parameter (-novals) can be set to a true value and
indicates to suppress the val attribute in each option element within
the optgroup.</p>
<p>See the discussion on optgroup at W3C
(<a href="http://www.w3.org/TR/REC-html40/interact/forms.html#edef-OPTGROUP">http://www.w3.org/TR/REC-html40/interact/forms.html#edef-OPTGROUP</a>)
for details.</p>
</li>
<li>
<p>An optional sixth parameter (-attributes) is provided to assign
any of the common HTML attributes to an individual menu item. It&#39;s
a pointer to a hash relating menu values to another
hash with the attribute&#39;s name as the key and the
attribute&#39;s value as the value.</p>
</li>
</ol>
<a name="CREATING-A-SCROLLING-LIST"></a><h2>CREATING A SCROLLING LIST</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">scrolling_list</span><span class="s">(</span><span class="q">&#39;list_name&#39;</span><span class="cm">,</span></li><li>				<span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>        <span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span><span class="n">5</span><span class="cm">,</span><span class="q">&#39;true&#39;</span><span class="cm">,</span><span class="s">{</span><span class="q">&#39;moe&#39;</span><span class="cm">=&gt;</span><span class="s">{</span><span class="q">&#39;class&#39;</span><span class="cm">=&gt;</span><span class="q">&#39;red&#39;</span><span class="s">}</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li><li>      -or-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">scrolling_list</span><span class="s">(</span><span class="q">&#39;list_name&#39;</span><span class="cm">,</span></li><li>				<span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>				<span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span><span class="n">5</span><span class="cm">,</span><span class="q">&#39;true&#39;</span><span class="cm">,</span></li><li>        \<span class="i">%labels</span><span class="cm">,</span><span class="i">%attributes</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">scrolling_list</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;list_name&#39;</span><span class="cm">,</span></li><li>				-<span class="w">values</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>				-<span class="w">default</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;moe&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>				-<span class="w">size</span><span class="cm">=&gt;</span><span class="n">5</span><span class="cm">,</span></li><li>				-<span class="w">multiple</span><span class="cm">=&gt;</span><span class="q">&#39;true&#39;</span><span class="cm">,</span></li><li>        -<span class="w">labels</span><span class="cm">=&gt;</span>\<span class="i">%labels</span><span class="cm">,</span></li><li>        -<span class="w">attributes</span><span class="cm">=&gt;</span>\<span class="i">%attributes</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>scrolling_list() creates a scrolling list.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first and second arguments are the list name (-name) and values
(-values).  As in the popup menu, the second argument should be an
array reference.</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The optional third argument (-default) can be either a reference to a
list containing the values to be selected by default, or can be a
single value to select.  If this argument is missing or undefined,
then nothing is selected when the list first appears.  In the named
parameter version, you can use the synonym &quot;-defaults&quot; for this
parameter.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional fourth argument is the size of the list (-size).</p>
</li>
<li><a name="4."></a><b>4.</b>
<p>The optional fifth argument can be set to true to allow multiple
simultaneous selections (-multiple).  Otherwise only one selection
will be allowed at a time.</p>
</li>
<li><a name="5."></a><b>5.</b>
<p>The optional sixth argument is a pointer to a hash
containing long user-visible labels for the list items (-labels).
If not provided, the values will be displayed.</p>
</li>
<li><a name="6."></a><b>6.</b>
<p>The optional sixth parameter (-attributes) is provided to assign
any of the common HTML attributes to an individual menu item. It&#39;s
a pointer to a hash relating menu values to another
hash with the attribute&#39;s name as the key and the
attribute&#39;s value as the value.</p>
<p>When this form is processed, all selected list items will be returned as
a list under the parameter name &#39;list_name&#39;.  The values of the
selected items can be retrieved with:</p>
<pre class="verbatim"><ol><li>      <span class="i">@selected</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;list_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
</ul>
<a name="CREATING-A-GROUP-OF-RELATED-CHECKBOXES"></a><h2>CREATING A GROUP OF RELATED CHECKBOXES</h2>
<pre class="verbatim"><ol><li>   print checkbox_group(-name=&gt;'group_name',</li><li>				-values=&gt;['eenie','meenie','minie','moe'],</li><li>				-default=&gt;['eenie','moe'],</li><li>				-linebreak=&gt;'true',</li><li>                                -disabled =&gt; ['moe'],</li><li>        -labels=&gt;\%labels,</li><li>        -attributes=&gt;\%attributes);</li><li></li><li>   print checkbox_group('group_name',</li><li>				['eenie','meenie','minie','moe'],</li><li>        ['eenie','moe'],'true',\%labels,</li><li>        {'moe'=&gt;{'class'=&gt;'red'}});</li><li></li><li>   HTML3-COMPATIBLE BROWSERS ONLY:</li><li></li><li>   print checkbox_group(-name=&gt;'group_name',</li><li>				-values=&gt;['eenie','meenie','minie','moe'],</li><li>				-rows=2,-columns=&gt;2);</li></ol></pre><p>checkbox_group() creates a list of checkboxes that are related
by the same name.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first and second arguments are the checkbox name and values,
respectively (-name and -values).  As in the popup menu, the second
argument should be an array reference.  These values are used for the
user-readable labels printed next to the checkboxes as well as for the
values passed to your script in the query string.</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The optional third argument (-default) can be either a reference to a
list containing the values to be checked by default, or can be a
single value to checked.  If this argument is missing or undefined,
then nothing is selected when the list first appears.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional fourth argument (-linebreak) can be set to true to place
line breaks between the checkboxes so that they appear as a vertical
list.  Otherwise, they will be strung together on a horizontal line.</p>
</li>
</ul>
<p>The optional <b>-labels</b> argument is a pointer to a hash
relating the checkbox values to the user-visible labels that will be
printed next to them.  If not provided, the values will be used as the
default.</p>
<p>The optional parameters <b>-rows</b>, and <b>-columns</b> cause
checkbox_group() to return an HTML3 compatible table containing the
checkbox group formatted with the specified number of rows and
columns.  You can provide just the -columns parameter if you wish;
checkbox_group will calculate the correct number of rows for you.</p>
<p>The option <b>-disabled</b> takes an array of checkbox values and disables
them by greying them out (this may not be supported by all browsers).</p>
<p>The optional <b>-attributes</b> argument is provided to assign any of the
common HTML attributes to an individual menu item. It&#39;s a pointer to
a hash relating menu values to another hash
with the attribute&#39;s name as the key and the attribute&#39;s value as the
value.</p>
<p>The optional <b>-tabindex</b> argument can be used to control the order in which
radio buttons receive focus when the user presses the tab button.  If
passed a scalar numeric value, the first element in the group will
receive this tab index and subsequent elements will be incremented by
one.  If given a reference to an array of radio button values, then
the indexes will be jiggered so that the order specified in the array
will correspond to the tab order.  You can also pass a reference to a
hash in which the hash keys are the radio button values and the values
are the tab indexes of each button.  Examples:</p>
<pre class="verbatim"><ol><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="n">100</span>    <span class="c">#  this group starts at index 100 and counts up</span></li><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="s">[</span><span class="q">&#39;moe&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="s">]</span>  <span class="c"># tab in this order</span></li><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="s">{</span><span class="w">meenie</span><span class="cm">=&gt;</span><span class="n">100</span><span class="cm">,</span><span class="w">moe</span><span class="cm">=&gt;</span><span class="n">101</span><span class="cm">,</span><span class="w">minie</span><span class="cm">=&gt;</span><span class="n">102</span><span class="cm">,</span><span class="w">eenie</span><span class="cm">=&gt;</span><span class="n">200</span><span class="s">}</span> <span class="c"># tab in this order</span></li></ol></pre><p>The optional <b>-labelattributes</b> argument will contain attributes
attached to the &lt;label&gt; element that surrounds each button.</p>
<p>When the form is processed, all checked boxes will be returned as
a list under the parameter name &#39;group_name&#39;.  The values of the
&quot;on&quot; checkboxes can be retrieved with:</p>
<pre class="verbatim"><ol><li>      <span class="i">@turned_on</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;group_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The value returned by checkbox_group() is actually an array of button
elements.  You can capture them and use them within tables, lists,
or in other creative ways:</p>
<pre class="verbatim"><ol><li>    <span class="i">@h</span> = <span class="i">checkbox_group</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;group_name&#39;</span><span class="cm">,</span>-<span class="w">values</span><span class="cm">=&gt;</span>\<span class="i">@values</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">&amp;use_in_creative_way</span><span class="s">(</span><span class="i">@h</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-STANDALONE-CHECKBOX"></a><h2>CREATING A STANDALONE CHECKBOX</h2>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">checkbox</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;checkbox_name&#39;</span><span class="cm">,</span></li><li>			   -<span class="w">checked</span><span class="cm">=&gt;</span><span class="n">1</span><span class="cm">,</span></li><li>			   -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;ON&#39;</span><span class="cm">,</span></li><li>			   -<span class="w">label</span><span class="cm">=&gt;</span><span class="q">&#39;CLICK ME&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or-</li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">checkbox</span><span class="s">(</span><span class="q">&#39;checkbox_name&#39;</span><span class="cm">,</span><span class="q">&#39;checked&#39;</span><span class="cm">,</span><span class="q">&#39;ON&#39;</span><span class="cm">,</span><span class="q">&#39;CLICK ME&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>checkbox() is used to create an isolated checkbox that isn&#39;t logically
related to any others.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first parameter is the required name for the checkbox (-name).  It
will also be used for the user-readable label printed next to the
checkbox.</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The optional second parameter (-checked) specifies that the checkbox
is turned on by default.  Synonyms are -selected and -on.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional third parameter (-value) specifies the value of the
checkbox when it is checked.  If not provided, the word &quot;on&quot; is
assumed.</p>
</li>
<li><a name="4."></a><b>4.</b>
<p>The optional fourth parameter (-label) is the user-readable label to
be attached to the checkbox.  If not provided, the checkbox name is
used.</p>
</li>
</ul>
<p>The value of the checkbox can be retrieved using:</p>
<pre class="verbatim"><ol><li>    <span class="i">$turned_on</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;checkbox_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-RADIO-BUTTON-GROUP"></a><h2>CREATING A RADIO BUTTON GROUP</h2>
<pre class="verbatim"><ol><li>   print radio_group(-name=&gt;'group_name',</li><li>			     -values=&gt;['eenie','meenie','minie'],</li><li>			     -default=&gt;'meenie',</li><li>			     -linebreak=&gt;'true',</li><li>           -labels=&gt;\%labels,</li><li>           -attributes=&gt;\%attributes);</li><li></li><li>	-or-</li><li></li><li>   print radio_group('group_name',['eenie','meenie','minie'],</li><li>            'meenie','true',\%labels,\%attributes);</li><li></li><li></li><li>   HTML3-COMPATIBLE BROWSERS ONLY:</li><li></li><li>   print radio_group(-name=&gt;'group_name',</li><li>			     -values=&gt;['eenie','meenie','minie','moe'],</li><li>			     -rows=2,-columns=&gt;2);</li></ol></pre><p>radio_group() creates a set of logically-related radio buttons
(turning one member of the group on turns the others off)</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first argument is the name of the group and is required (-name).</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The second argument (-values) is the list of values for the radio
buttons.  The values and the labels that appear on the page are
identical.  Pass an array <i>reference</i> in the second argument, either
using an anonymous array, as shown, or by referencing a named array as
in &quot;\@foo&quot;.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>The optional third parameter (-default) is the name of the default
button to turn on. If not specified, the first item will be the
default.  You can provide a nonexistent button name, such as &quot;-&quot; to
start up with no buttons selected.</p>
</li>
<li><a name="4."></a><b>4.</b>
<p>The optional fourth parameter (-linebreak) can be set to &#39;true&#39; to put
line breaks between the buttons, creating a vertical list.</p>
</li>
<li><a name="5."></a><b>5.</b>
<p>The optional fifth parameter (-labels) is a pointer to an associative
array relating the radio button values to user-visible labels to be
used in the display.  If not provided, the values themselves are
displayed.</p>
</li>
</ul>
<p>All modern browsers can take advantage of the optional parameters
<b>-rows</b>, and <b>-columns</b>.  These parameters cause radio_group() to
return an HTML3 compatible table containing the radio group formatted
with the specified number of rows and columns.  You can provide just
the -columns parameter if you wish; radio_group will calculate the
correct number of rows for you.</p>
<p>To include row and column headings in the returned table, you
can use the <b>-rowheaders</b> and <b>-colheaders</b> parameters.  Both
of these accept a pointer to an array of headings to use.
The headings are just decorative.  They don&#39;t reorganize the
interpretation of the radio buttons -- they&#39;re still a single named
unit.</p>
<p>The optional <b>-tabindex</b> argument can be used to control the order in which
radio buttons receive focus when the user presses the tab button.  If
passed a scalar numeric value, the first element in the group will
receive this tab index and subsequent elements will be incremented by
one.  If given a reference to an array of radio button values, then
the indexes will be jiggered so that the order specified in the array
will correspond to the tab order.  You can also pass a reference to a
hash in which the hash keys are the radio button values and the values
are the tab indexes of each button.  Examples:</p>
<pre class="verbatim"><ol><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="n">100</span>    <span class="c">#  this group starts at index 100 and counts up</span></li><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="s">[</span><span class="q">&#39;moe&#39;</span><span class="cm">,</span><span class="q">&#39;minie&#39;</span><span class="cm">,</span><span class="q">&#39;eenie&#39;</span><span class="cm">,</span><span class="q">&#39;meenie&#39;</span><span class="s">]</span>  <span class="c"># tab in this order</span></li><li>  -<span class="w">tabindex</span> <span class="cm">=&gt;</span> <span class="s">{</span><span class="w">meenie</span><span class="cm">=&gt;</span><span class="n">100</span><span class="cm">,</span><span class="w">moe</span><span class="cm">=&gt;</span><span class="n">101</span><span class="cm">,</span><span class="w">minie</span><span class="cm">=&gt;</span><span class="n">102</span><span class="cm">,</span><span class="w">eenie</span><span class="cm">=&gt;</span><span class="n">200</span><span class="s">}</span> <span class="c"># tab in this order</span></li></ol></pre><p>The optional <b>-attributes</b> argument is provided to assign any of the
common HTML attributes to an individual menu item. It&#39;s a pointer to
a hash relating menu values to another hash
with the attribute&#39;s name as the key and the attribute&#39;s value as the
value.</p>
<p>The optional <b>-labelattributes</b> argument will contain attributes
attached to the &lt;label&gt; element that surrounds each button.</p>
<p>When the form is processed, the selected radio button can
be retrieved using:</p>
<pre class="verbatim"><ol><li>      <span class="i">$which_radio_button</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;group_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The value returned by radio_group() is actually an array of button
elements.  You can capture them and use them within tables, lists,
or in other creative ways:</p>
<pre class="verbatim"><ol><li>    <span class="i">@h</span> = <span class="i">radio_group</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;group_name&#39;</span><span class="cm">,</span>-<span class="w">values</span><span class="cm">=&gt;</span>\<span class="i">@values</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">&amp;use_in_creative_way</span><span class="s">(</span><span class="i">@h</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-SUBMIT-BUTTON"></a><h2>CREATING A SUBMIT BUTTON</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">submit</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span></li><li>			-<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;value&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or-</li><li></li><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">submit</span><span class="s">(</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span><span class="q">&#39;value&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>submit() will create the query submission button.  Every form
should have one of these.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first argument (-name) is optional.  You can give the button a
name if you have several submission buttons in your form and you want
to distinguish between them.</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The second argument (-value) is also optional.  This gives the button
a value that will be passed to your script in the query string. The
name will also be used as the user-visible label.</p>
</li>
<li><a name="3."></a><b>3.</b>
<p>You can use -label as an alias for -value.  I always get confused
about which of -name and -value changes the user-visible label on the
button.</p>
</li>
</ul>
<p>You can figure out which button was pressed by using different
values for each one:</p>
<pre class="verbatim"><ol><li>     <span class="i">$which_one</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;button_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-RESET-BUTTON"></a><h2>CREATING A RESET BUTTON</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/reset.html">reset</a></li></ol></pre><p>reset() creates the &quot;reset&quot; button.  Note that it restores the
form to its value from the last time the script was called, 
NOT necessarily to the defaults.</p>
<p>Note that this conflicts with the Perl reset() built-in.  Use
CORE::reset() to get the original reset function.</p>
<a name="CREATING-A-DEFAULT-BUTTON"></a><h2>CREATING A DEFAULT BUTTON</h2>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/print.html">print</a> <span class="i">defaults</span><span class="s">(</span><span class="q">&#39;button_label&#39;</span><span class="s">)</span></li></ol></pre><p>defaults() creates a button that, when invoked, will cause the
form to be completely reset to its defaults, wiping out all the
changes the user ever made.</p>
<a name="CREATING-A-HIDDEN-FIELD"></a><h2>CREATING A HIDDEN FIELD</h2>
<pre class="verbatim"><ol><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">hidden</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;hidden_name&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">default</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;value1&#39;</span><span class="cm">,</span><span class="q">&#39;value2&#39;</span>...<span class="s">]</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>		-or-</li><li></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">hidden</span><span class="s">(</span><span class="q">&#39;hidden_name&#39;</span><span class="cm">,</span><span class="q">&#39;value1&#39;</span><span class="cm">,</span><span class="q">&#39;value2&#39;</span>...<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>hidden() produces a text field that can&#39;t be seen by the user.  It
is useful for passing state variable information from one invocation
of the script to the next.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first argument is required and specifies the name of this
field (-name).</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The second argument is also required and specifies its value
(-default).  In the named parameter style of calling, you can provide
a single value here or a reference to a whole list</p>
</li>
</ul>
<p>Fetch the value of a hidden field this way:</p>
<pre class="verbatim"><ol><li>     <span class="i">$hidden_value</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;hidden_name&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Note, that just like all the other form elements, the value of a
hidden field is &quot;sticky&quot;.  If you want to replace a hidden field with
some other values after the script has been called once you&#39;ll have to
do it manually:</p>
<pre class="verbatim"><ol><li>     <span class="i">param</span><span class="s">(</span><span class="q">&#39;hidden_name&#39;</span><span class="cm">,</span><span class="q">&#39;new&#39;</span><span class="cm">,</span><span class="q">&#39;values&#39;</span><span class="cm">,</span><span class="q">&#39;here&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="CREATING-A-CLICKABLE-IMAGE-BUTTON"></a><h2>CREATING A CLICKABLE IMAGE BUTTON</h2>
<pre class="verbatim"><ol><li>     <a class="l_k" href="functions/print.html">print</a> <span class="i">image_button</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span></li><li>				-<span class="w">src</span><span class="cm">=&gt;</span><span class="q">&#39;/source/URL&#39;</span><span class="cm">,</span></li><li>				-<span class="w">align</span><span class="cm">=&gt;</span><span class="q">&#39;MIDDLE&#39;</span><span class="s">)</span><span class="sc">;</span>      </li><li></li><li>	-or-</li><li></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="i">image_button</span><span class="s">(</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span><span class="q">&#39;/source/URL&#39;</span><span class="cm">,</span><span class="q">&#39;MIDDLE&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>image_button() produces a clickable image.  When it&#39;s clicked on the
position of the click is returned to your script as &quot;button_name.x&quot;
and &quot;button_name.y&quot;, where &quot;button_name&quot; is the name you&#39;ve assigned
to it.</p>
<ul>
<li><a name="*Parameters%3a*"></a><b><b>Parameters:</b></b>
</li>
<li><a name="1."></a><b>1.</b>
<p>The first argument (-name) is required and specifies the name of this
field.</p>
</li>
<li><a name="2."></a><b>2.</b>
<p>The second argument (-src) is also required and specifies the URL</p>
</li>
<li><a name="3.-The-third-option-(-align%2c-optional)-is-an-alignment-type%2c-and-may-be-TOP%2c-BOTTOM-or-MIDDLE"></a><b>3.
The third option (-align, optional) is an alignment type, and may be
TOP, BOTTOM or MIDDLE</b>
</li>
</ul>
<p>Fetch the value of the button this way:
     $x = param(&#39;button_name.x&#39;);
     $y = param(&#39;button_name.y&#39;);</p>
<a name="CREATING-A-JAVASCRIPT-ACTION-BUTTON"></a><h2>CREATING A JAVASCRIPT ACTION BUTTON</h2>
<pre class="verbatim"><ol><li>     <a class="l_k" href="functions/print.html">print</a> <span class="i">button</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span></li><li>			  -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;user visible label&#39;</span><span class="cm">,</span></li><li>			  -<span class="w">onClick</span><span class="cm">=&gt;</span><span class="q">&quot;do_something()&quot;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>	-or-</li><li></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="i">button</span><span class="s">(</span><span class="q">&#39;button_name&#39;</span><span class="cm">,</span><span class="q">&quot;do_something()&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>button() produces a button that is compatible with Netscape 2.0&#39;s
JavaScript.  When it&#39;s pressed the fragment of JavaScript code
pointed to by the <b>-onClick</b> parameter will be executed.</p>
<a name="HTTP-COOKIES"></a><h1>HTTP COOKIES</h1>
<p>Browsers support a so-called &quot;cookie&quot; designed to help maintain state
within a browser session.  CGI.pm has several methods that support
cookies.</p>
<p>A cookie is a name=value pair much like the named parameters in a CGI
query string.  CGI scripts create one or more cookies and send
them to the browser in the HTTP header.  The browser maintains a list
of cookies that belong to a particular Web server, and returns them
to the CGI script during subsequent interactions.</p>
<p>In addition to the required name=value pair, each cookie has several
optional attributes:</p>
<ol>
<li><a name="1.-an-expiration-time"></a><b>an expiration time</b>
<p>This is a time/date string (in a special GMT format) that indicates
when a cookie expires.  The cookie will be saved and returned to your
script until this expiration date is reached if the user exits
the browser and restarts it.  If an expiration date isn&#39;t specified, the cookie
will remain active until the user quits the browser.</p>
</li>
<li><a name="2.-a-domain"></a><b>a domain</b>
<p>This is a partial or complete domain name for which the cookie is 
valid.  The browser will return the cookie to any host that matches
the partial domain name.  For example, if you specify a domain name
of &quot;.capricorn.com&quot;, then the browser will return the cookie to
Web servers running on any of the machines &quot;www.capricorn.com&quot;, 
&quot;www2.capricorn.com&quot;, &quot;feckless.capricorn.com&quot;, etc.  Domain names
must contain at least two periods to prevent attempts to match
on top level domains like &quot;.edu&quot;.  If no domain is specified, then
the browser will only return the cookie to servers on the host the
cookie originated from.</p>
</li>
<li><a name="3.-a-path"></a><b>a path</b>
<p>If you provide a cookie path attribute, the browser will check it
against your script&#39;s URL before returning the cookie.  For example,
if you specify the path &quot;/cgi-bin&quot;, then the cookie will be returned
to each of the scripts &quot;/cgi-bin/tally.pl&quot;, &quot;/cgi-bin/order.pl&quot;,
and &quot;/cgi-bin/customer_service/complain.pl&quot;, but not to the script
&quot;/cgi-private/site_admin.pl&quot;.  By default, path is set to &quot;/&quot;, which
causes the cookie to be sent to any CGI script on your site.</p>
</li>
<li><a name="4.-a-%22secure%22-flag"></a><b>a &quot;secure&quot; flag</b>
<p>If the &quot;secure&quot; attribute is set, the cookie will only be sent to your
script if the CGI request is occurring on a secure channel, such as SSL.</p>
</li>
</ol>
<p>The interface to HTTP cookies is the <b>cookie()</b> method:</p>
<pre class="verbatim"><ol><li>    <span class="i">$cookie</span> = <span class="i">cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;sessionID&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;xyzzy&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">expires</span><span class="cm">=&gt;</span><span class="q">&#39;+1h&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">path</span><span class="cm">=&gt;</span><span class="q">&#39;/cgi-bin/database&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">domain</span><span class="cm">=&gt;</span><span class="q">&#39;.capricorn.org&#39;</span><span class="cm">,</span></li><li>			     -<span class="w">secure</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">cookie</span><span class="cm">=&gt;</span><span class="i">$cookie</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><b>cookie()</b> creates a new cookie.  Its parameters include:</p>
<ul>
<li><a name="*-name*"></a><b><b>-name</b></b>
<p>The name of the cookie (required).  This can be any string at all.
Although browsers limit their cookie names to non-whitespace
alphanumeric characters, CGI.pm removes this restriction by escaping
and unescaping cookies behind the scenes.</p>
</li>
<li><a name="*-value*"></a><b><b>-value</b></b>
<p>The value of the cookie.  This can be any scalar value,
array reference, or even hash reference.  For example,
you can store an entire hash into a cookie this way:</p>
<pre class="verbatim"><ol><li>	<span class="i">$cookie</span>=<span class="i">cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;family information&#39;</span><span class="cm">,</span></li><li>			       -<span class="w">value</span><span class="cm">=&gt;</span>\<span class="i">%childrens_ages</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="*-path*"></a><b><b>-path</b></b>
<p>The optional partial path for which this cookie will be valid, as described
above.</p>
</li>
<li><a name="*-domain*"></a><b><b>-domain</b></b>
<p>The optional partial domain for which this cookie will be valid, as described
above.</p>
</li>
<li><a name="*-expires*"></a><b><b>-expires</b></b>
<p>The optional expiration date for this cookie.  The format is as described 
in the section on the <b>header()</b> method:</p>
<pre class="verbatim"><ol><li>	"+1h"  one hour from now</li></ol></pre></li>
<li><a name="*-secure*"></a><b><b>-secure</b></b>
<p>If set to true, this cookie will only be used within a secure
SSL session.</p>
</li>
</ul>
<p>The cookie created by cookie() must be incorporated into the HTTP
header within the string returned by the header() method:</p>
<pre class="verbatim"><ol><li>        <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">':standard'</span><span class="sc">;</span></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">cookie</span><span class="cm">=&gt;</span><span class="i">$my_cookie</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>To create multiple cookies, give header() an array reference:</p>
<pre class="verbatim"><ol><li>	<span class="i">$cookie1</span> = <span class="i">cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;riddle_name&#39;</span><span class="cm">,</span></li><li>				  -<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&quot;The Sphynx&#39;s Question&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>	<span class="i">$cookie2</span> = <span class="i">cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;answers&#39;</span><span class="cm">,</span></li><li>				  -<span class="w">value</span><span class="cm">=&gt;</span>\<span class="i">%answers</span><span class="s">)</span><span class="sc">;</span></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">cookie</span><span class="cm">=&gt;</span><span class="s">[</span><span class="i">$cookie1</span><span class="cm">,</span><span class="i">$cookie2</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>To retrieve a cookie, request it by name by calling cookie() method
without the <b>-value</b> parameter. This example uses the object-oriented
form:</p>
<pre class="verbatim"><ol><li>	<a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span><span class="sc">;</span></li><li>	<span class="i">$query</span> = <span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>	<span class="i">$riddle</span> = <span class="i">$query</span><span class="i">-&gt;cookie</span><span class="s">(</span><span class="q">'riddle_name'</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="i">%answers</span> = <span class="i">$query</span><span class="i">-&gt;cookie</span><span class="s">(</span><span class="q">'answers'</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Cookies created with a single scalar value, such as the &quot;riddle_name&quot;
cookie, will be returned in that form.  Cookies with array and hash
values can also be retrieved.</p>
<p>The cookie and CGI namespaces are separate.  If you have a parameter
named &#39;answers&#39; and a cookie named &#39;answers&#39;, the values retrieved by
param() and cookie() are independent of each other.  However, it&#39;s
simple to turn a CGI parameter into a cookie, and vice-versa:</p>
<pre class="verbatim"><ol><li>   <span class="c"># turn a CGI parameter into a cookie</span></li><li>   <span class="i">$c</span>=<span class="i">cookie</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;answers&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="s">[</span><span class="i">param</span><span class="s">(</span><span class="q">&#39;answers&#39;</span><span class="s">)</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="c"># vice-versa</span></li><li>   <span class="i">param</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;answers&#39;</span><span class="cm">,</span>-<span class="w">value</span><span class="cm">=&gt;</span><span class="s">[</span><span class="i">cookie</span><span class="s">(</span><span class="q">&#39;answers&#39;</span><span class="s">)</span><span class="s">]</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you call cookie() without any parameters, it will return a list of
the names of all cookies passed to your script:</p>
<pre class="verbatim"><ol><li>  <span class="i">@cookies</span> = <span class="i">cookie</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>See the <b>cookie.cgi</b> example script for some ideas on how to use
cookies effectively.</p>
<a name="WORKING-WITH-FRAMES"></a><h1>WORKING WITH FRAMES</h1>
<p>It&#39;s possible for CGI.pm scripts to write into several browser panels
and windows using the HTML 4 frame mechanism.  There are three
techniques for defining new frames programmatically:</p>
<ol>
<li><a name="1.-Create-a-%3cFrameset%3e-document"></a><b>Create a &lt;Frameset&gt; document</b>
<p>After writing out the HTTP header, instead of creating a standard
HTML document using the start_html() call, create a &lt;frameset&gt; 
document that defines the frames on the page.  Specify your script(s)
(with appropriate parameters) as the SRC for each of the frames.</p>
<p>There is no specific support for creating &lt;frameset&gt; sections 
in CGI.pm, but the HTML is very simple to write.  See the frame
documentation in Netscape&#39;s home pages for details</p>
<pre class="verbatim"><ol><li>  http://wp.netscape.com/assist/net_sites/frames.html</li></ol></pre></li>
<li><a name="2.-Specify-the-destination-for-the-document-in-the-HTTP-header"></a><b>Specify the destination for the document in the HTTP header</b>
<p>You may provide a <b>-target</b> parameter to the header() method:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">target</span><span class="cm">=&gt;</span><span class="q">&#39;ResultsWindow&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This will tell the browser to load the output of your script into the
frame named &quot;ResultsWindow&quot;.  If a frame of that name doesn&#39;t already
exist, the browser will pop up a new window and load your script&#39;s
document into that.  There are a number of magic names that you can
use for targets.  See the frame documents on Netscape&#39;s home pages for
details.</p>
</li>
<li><a name="3.-Specify-the-destination-for-the-document-in-the-%3cform%3e-tag"></a><b>Specify the destination for the document in the &lt;form&gt; tag</b>
<p>You can specify the frame to load in the FORM tag itself.  With
CGI.pm it looks like this:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">start_form</span><span class="s">(</span>-<span class="w">target</span><span class="cm">=&gt;</span><span class="q">&#39;ResultsWindow&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>When your script is reinvoked by the form, its output will be loaded
into the frame named &quot;ResultsWindow&quot;.  If one doesn&#39;t already exist
a new window will be created.</p>
</li>
</ol>
<p>The script &quot;frameset.cgi&quot; in the examples directory shows one way to
create pages in which the fill-out form and the response live in
side-by-side frames.</p>
<a name="SUPPORT-FOR-JAVASCRIPT"></a><h1>SUPPORT FOR JAVASCRIPT</h1>
<p>The usual way to use JavaScript is to define a set of functions in a
&lt;SCRIPT&gt; block inside the HTML header and then to register event
handlers in the various elements of the page. Events include such
things as the mouse passing over a form element, a button being
clicked, the contents of a text field changing, or a form being
submitted. When an event occurs that involves an element that has
registered an event handler, its associated JavaScript code gets
called.</p>
<p>The elements that can register event handlers include the &lt;BODY&gt; of an
HTML document, hypertext links, all the various elements of a fill-out
form, and the form itself. There are a large number of events, and
each applies only to the elements for which it is relevant. Here is a
partial list:</p>
<ul>
<li><a name="*onLoad*"></a><b><b>onLoad</b></b>
<p>The browser is loading the current document. Valid in:</p>
<pre class="verbatim"><ol><li>     + The HTML &lt;BODY&gt; section only.</li></ol></pre></li>
<li><a name="*onUnload*"></a><b><b>onUnload</b></b>
<p>The browser is closing the current page or frame. Valid for:</p>
<pre class="verbatim"><ol><li>     + The HTML &lt;BODY&gt; section only.</li></ol></pre></li>
<li><a name="*onSubmit*"></a><b><b>onSubmit</b></b>
<p>The user has pressed the submit button of a form. This event happens
just before the form is submitted, and your function can return a
value of false in order to abort the submission.  Valid for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Forms</span> <span class="w">only</span>.</li></ol></pre></li>
<li><a name="*onClick*"></a><b><b>onClick</b></b>
<p>The mouse has clicked on an item in a fill-out form. Valid for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Buttons</span> <span class="s">(</span><span class="w">including</span> <span class="w">submit</span><span class="cm">,</span> <a class="l_k" href="functions/reset.html">reset</a><span class="cm">,</span> and <span class="w">image</span> <span class="w">buttons</span><span class="s">)</span></li><li>     + <span class="w">Checkboxes</span></li><li>     + <span class="w">Radio</span> <span class="w">buttons</span></li></ol></pre></li>
<li><a name="*onChange*"></a><b><b>onChange</b></b>
<p>The user has changed the contents of a field. Valid for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li><li>     + <span class="w">Popup</span> <span class="w">Menus</span></li><li>     + <span class="w">Scrolling</span> <span class="w">lists</span></li></ol></pre></li>
<li><a name="*onFocus*"></a><b><b>onFocus</b></b>
<p>The user has selected a field to work with. Valid for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li><li>     + <span class="w">Popup</span> <span class="w">Menus</span></li><li>     + <span class="w">Scrolling</span> <span class="w">lists</span></li></ol></pre></li>
<li><a name="*onBlur*"></a><b><b>onBlur</b></b>
<p>The user has deselected a field (gone to work somewhere else).  Valid
for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li><li>     + <span class="w">Popup</span> <span class="w">Menus</span></li><li>     + <span class="w">Scrolling</span> <span class="w">lists</span></li></ol></pre></li>
<li><a name="*onSelect*"></a><b><b>onSelect</b></b>
<p>The user has changed the part of a text field that is selected.  Valid
for:</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li></ol></pre></li>
<li><a name="*onMouseOver*"></a><b><b>onMouseOver</b></b>
<p>The mouse has moved over an element.</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li><li>     + <span class="w">Popup</span> <span class="w">Menus</span></li><li>     + <span class="w">Scrolling</span> <span class="w">lists</span></li></ol></pre></li>
<li><a name="*onMouseOut*"></a><b><b>onMouseOut</b></b>
<p>The mouse has moved off an element.</p>
<pre class="verbatim"><ol><li>     + <span class="w">Text</span> <span class="w">fields</span></li><li>     + <span class="w">Text</span> <span class="w">areas</span></li><li>     + <span class="w">Password</span> <span class="w">fields</span></li><li>     + <span class="w">File</span> <span class="w">fields</span></li><li>     + <span class="w">Popup</span> <span class="w">Menus</span></li><li>     + <span class="w">Scrolling</span> <span class="w">lists</span></li></ol></pre></li>
</ul>
<p>In order to register a JavaScript event handler with an HTML element,
just use the event name as a parameter when you call the corresponding
CGI method. For example, to have your validateAge() JavaScript code
executed every time the textfield named &quot;age&quot; changes, generate the
field like this:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/print.html">print</a> <span class="i">textfield</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;age&#39;</span><span class="cm">,</span>-<span class="w">onChange</span><span class="cm">=&gt;</span><span class="q">&quot;validateAge(this)&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This example assumes that you&#39;ve already declared the validateAge()
function by incorporating it into a &lt;SCRIPT&gt; block. The CGI.pm
start_html() method provides a convenient way to create this section.</p>
<p>Similarly, you can create a form that checks itself over for
consistency and alerts the user if some essential value is missing by
creating it this way: 
  print startform(-onSubmit=&gt;&quot;validateMe(this)&quot;);</p>
<p>See the javascript.cgi script for a demonstration of how this all
works.</p>
<a name="LIMITED-SUPPORT-FOR-CASCADING-STYLE-SHEETS"></a><h1>LIMITED SUPPORT FOR CASCADING STYLE SHEETS</h1>
<p>CGI.pm has limited support for HTML3&#39;s cascading style sheets (css).
To incorporate a stylesheet into your document, pass the
start_html() method a <b>-style</b> parameter.  The value of this
parameter may be a scalar, in which case it is treated as the source
URL for the stylesheet, or it may be a hash reference.  In the latter
case you should provide the hash with one or more of <b>-src</b> or
<b>-code</b>.  <b>-src</b> points to a URL where an externally-defined
stylesheet can be found.  <b>-code</b> points to a scalar value to be
incorporated into a &lt;style&gt; section.  Style definitions in <b>-code</b>
override similarly-named ones in <b>-src</b>, hence the name &quot;cascading.&quot;</p>
<p>You may also specify the type of the stylesheet by adding the optional
<b>-type</b> parameter to the hash pointed to by <b>-style</b>.  If not
specified, the style defaults to &#39;text/css&#39;.</p>
<p>To refer to a style within the body of your document, add the
<b>-class</b> parameter to any HTML element:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">h1</span><span class="s">(</span><span class="s">{</span>-<span class="w">class</span><span class="cm">=&gt;</span><span class="q">&#39;Fancy&#39;</span><span class="s">}</span><span class="cm">,</span><span class="q">&#39;Welcome to the Party&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Or define styles on the fly with the <b>-style</b> parameter:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">h1</span><span class="s">(</span><span class="s">{</span>-<span class="w">style</span><span class="cm">=&gt;</span><span class="q">&#39;Color: red;&#39;</span><span class="s">}</span><span class="cm">,</span><span class="q">&#39;Welcome to Hell&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>You may also use the new <b>span()</b> element to apply a style to a
section of text:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">span</span><span class="s">(</span><span class="s">{</span>-<span class="w">style</span><span class="cm">=&gt;</span><span class="q">&#39;Color: red;&#39;</span><span class="s">}</span><span class="cm">,</span></li><li>	       <span class="i">h1</span><span class="s">(</span><span class="q">&#39;Welcome to Hell&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>	       <span class="q">&quot;Where did that handbasket get to?&quot;</span></li><li>	       <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Note that you must import the &quot;:html3&quot; definitions to have the
<b>span()</b> method available.  Here&#39;s a quick and dirty example of using
CSS&#39;s.  See the CSS specification at
<a href="http://www.w3.org/pub/WWW/TR/Wd-css-1.html">http://www.w3.org/pub/WWW/TR/Wd-css-1.html</a> for more information.</p>
<pre class="verbatim"><ol><li>    use CGI qw/:standard :html3/;</li><li></li><li>    #here's a stylesheet incorporated directly into the page</li><li>    $newStyle=&lt;&lt;END;</li><li>    &lt;!-- </li><li>    P.Tip {</li><li>	margin-right: 50pt;</li><li>	margin-left: 50pt;</li><li>        color: red;</li><li>    }</li><li>    P.Alert {</li><li>	font-size: 30pt;</li><li>        font-family: sans-serif;</li><li>      color: red;</li><li>    }</li><li>    --&gt;</li><li>    END</li><li>    print header();</li><li>    print start_html( -title=&gt;'CGI with Style',</li><li>		      -style=&gt;{-src=&gt;'http://www.capricorn.com/style/st1.css',</li><li>		               -code=&gt;$newStyle}</li><li>	             );</li><li>    print h1('CGI with Style'),</li><li>          p({-class=&gt;'Tip'},</li><li>	    "Better read the cascading style sheet spec before playing with this!"),</li><li>          span({-style=&gt;'color: magenta'},</li><li>	       "Look Mom, no hands!",</li><li>	       p(),</li><li>	       "Whooo wee!"</li><li>	       );</li><li>    print end_html;</li></ol></pre><p>Pass an array reference to <b>-code</b> or <b>-src</b> in order to incorporate
multiple stylesheets into your document.</p>
<p>Should you wish to incorporate a verbatim stylesheet that includes
arbitrary formatting in the header, you may pass a -verbatim tag to
the -style hash, as follows:</p>
<p>print start_html (-style  =&gt;  {-verbatim =&gt; &#39;@import url(&quot;/server-common/css/&#39;.$cssFile.&#39;&quot;);&#39;,
                  -src    =&gt;  &#39;/server-common/css/core.css&#39;});</p>
<p>This will generate an HTML header that contains this:</p>
<pre class="verbatim"><ol><li> &lt;link rel="stylesheet" type="text/css"  href="/server-common/css/core.css"&gt;</li><li>   &lt;style type="text/css"&gt;</li><li>   @import url("/server-common/css/main.css");</li><li>   &lt;/style&gt;</li></ol></pre><p>Any additional arguments passed in the -style value will be
incorporated into the &lt;link&gt; tag.  For example:</p>
<pre class="verbatim"><ol><li> <span class="i">start_html</span><span class="s">(</span>-<span class="w">style</span><span class="cm">=&gt;</span><span class="s">{</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="s">[</span><span class="q">&#39;/styles/print.css&#39;</span><span class="cm">,</span><span class="q">&#39;/styles/layout.css&#39;</span><span class="s">]</span><span class="cm">,</span></li><li>			  -<span class="w">media</span> <span class="cm">=&gt;</span> <span class="q">&#39;all&#39;</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This will give:</p>
<pre class="verbatim"><ol><li> &lt;link rel="stylesheet" type="text/css" href="/styles/print.css" media="all"/&gt;</li><li> &lt;link rel="stylesheet" type="text/css" href="/styles/layout.css" media="all"/&gt;</li></ol></pre><p>&lt;p&gt;</p>
<p>To make more complicated &lt;link&gt; tags, use the Link() function
and pass it to start_html() in the -head argument, as in:</p>
<pre class="verbatim"><ol><li>  <span class="i">@h</span> = <span class="s">(</span><span class="i">Link</span><span class="s">(</span><span class="s">{</span>-<span class="w">rel</span><span class="cm">=&gt;</span><span class="q">&#39;stylesheet&#39;</span><span class="cm">,</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;text/css&#39;</span><span class="cm">,</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="q">&#39;/ss/ss.css&#39;</span><span class="cm">,</span>-<span class="w">media</span><span class="cm">=&gt;</span><span class="q">&#39;all&#39;</span><span class="s">}</span><span class="s">)</span><span class="cm">,</span></li><li>        <span class="i">Link</span><span class="s">(</span><span class="s">{</span>-<span class="w">rel</span><span class="cm">=&gt;</span><span class="q">&#39;stylesheet&#39;</span><span class="cm">,</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;text/css&#39;</span><span class="cm">,</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="q">&#39;/ss/fred.css&#39;</span><span class="cm">,</span>-<span class="w">media</span><span class="cm">=&gt;</span><span class="q">&#39;paper&#39;</span><span class="s">}</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">start_html</span><span class="s">(</span><span class="s">{</span>-<span class="w">head</span><span class="cm">=&gt;</span>\<span class="i">@h</span><span class="s">}</span><span class="s">)</span></li></ol></pre><p>To create primary and  &quot;alternate&quot; stylesheet, use the <b>-alternate</b> option:</p>
<pre class="verbatim"><ol><li> <span class="i">start_html</span><span class="s">(</span>-<span class="w">style</span><span class="cm">=&gt;</span><span class="s">{</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="s">[</span></li><li>                           <span class="s">{</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="q">'/styles/print.css'</span><span class="s">}</span><span class="cm">,</span></li><li>			   <span class="s">{</span>-<span class="w">src</span><span class="cm">=&gt;</span><span class="q">'/styles/alt.css'</span><span class="cm">,</span>-<span class="w">alternate</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">}</span></li><li>                           <span class="s">]</span></li><li>		    <span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="DEBUGGING"></a><h1>DEBUGGING</h1>
<p>If you are running the script from the command line or in the perl
debugger, you can pass the script a list of keywords or
parameter=value pairs on the command line or from standard input (you
don&#39;t have to worry about tricking your script into reading from
environment variables).  You can pass keywords like this:</p>
<pre class="verbatim"><ol><li>    <span class="w">your_script</span>.<span class="w">pl</span> <span class="w">keyword1</span> <span class="w">keyword2</span> <span class="w">keyword3</span></li></ol></pre><p>or this:</p>
<pre class="verbatim"><ol><li>   <span class="w">your_script</span>.<span class="w">pl</span> <span class="w">keyword1</span>+<span class="w">keyword2</span>+<span class="w">keyword3</span></li></ol></pre><p>or this:</p>
<pre class="verbatim"><ol><li>    <span class="w">your_script</span>.<span class="w">pl</span> <span class="w">name1</span>=<span class="w">value1</span> <span class="w">name2</span>=<span class="w">value2</span></li></ol></pre><p>or this:</p>
<pre class="verbatim"><ol><li>    <span class="w">your_script</span>.<span class="w">pl</span> <span class="w">name1</span>=<span class="w">value1</span><span class="i">&amp;name2</span>=<span class="w">value2</span></li></ol></pre><p>To turn off this feature, use the -no_debug pragma.</p>
<p>To test the POST method, you may enable full debugging with the -debug
pragma.  This will allow you to feed newline-delimited name=value
pairs to the script on standard input.</p>
<p>When debugging, you can use quotes and backslashes to escape 
characters in the familiar shell manner, letting you place
spaces and other funny characters in your parameter=value
pairs:</p>
<pre class="verbatim"><ol><li>   your_script.pl "name1='I am a long value'" "name2=two\ words"</li></ol></pre><p>Finally, you can set the path info for the script by prefixing the first
name/value parameter with the path followed by a question mark (?):</p>
<pre class="verbatim"><ol><li>    your_script.pl /your/path/here?name1=value1&amp;name2=value2</li></ol></pre><a name="DUMPING-OUT-ALL-THE-NAME%2fVALUE-PAIRS"></a><h2>DUMPING OUT ALL THE NAME/VALUE PAIRS</h2>
<p>The Dump() method produces a string consisting of all the query&#39;s
name/value pairs formatted nicely as a nested list.  This is useful
for debugging purposes:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">Dump</span></li></ol></pre><p>Produces something that looks like:</p>
<pre class="verbatim"><ol><li>    &lt;ul&gt;</li><li>    &lt;li&gt;name1</li><li>	&lt;ul&gt;</li><li>	&lt;li&gt;value1</li><li>	&lt;li&gt;value2</li><li>	&lt;/ul&gt;</li><li>    &lt;li&gt;name2</li><li>	&lt;ul&gt;</li><li>	&lt;li&gt;value1</li><li>	&lt;/ul&gt;</li><li>    &lt;/ul&gt;</li></ol></pre><p>As a shortcut, you can interpolate the entire CGI object into a string
and it will be replaced with the a nice HTML dump shown above:</p>
<pre class="verbatim"><ol><li>    <span class="i">$query</span>=<span class="w">new</span> <span class="w">CGI</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;&lt;h2&gt;Current Values&lt;/h2&gt; $query\n&quot;</span><span class="sc">;</span></li></ol></pre><a name="FETCHING-ENVIRONMENT-VARIABLES"></a><h1>FETCHING ENVIRONMENT VARIABLES</h1>
<p>Some of the more useful environment variables can be fetched
through this interface.  The methods are as follows:</p>
<ul>
<li><a name="*Accept()*"></a><b><b>Accept()</b></b>
<p>Return a list of MIME types that the remote browser accepts. If you
give this method a single argument corresponding to a MIME type, as in
Accept(&#39;text/html&#39;), it will return a floating point value
corresponding to the browser&#39;s preference for this type from 0.0
(don&#39;t want) to 1.0.  Glob types (e.g. text/*) in the browser&#39;s accept
list are handled correctly.</p>
<p>Note that the capitalization changed between version 2.43 and 2.44 in
order to avoid conflict with Perl&#39;s accept() function.</p>
</li>
<li><a name="*raw_cookie()*"></a><b><b>raw_cookie()</b></b>
<p>Returns the HTTP_COOKIE variable.  Cookies have a special format, and
this method call just returns the raw form (?cookie dough).  See
cookie() for ways of setting and retrieving cooked cookies.</p>
<p>Called with no parameters, raw_cookie() returns the packed cookie
structure.  You can separate it into individual cookies by splitting
on the character sequence &quot;; &quot;.  Called with the name of a cookie,
retrieves the <b>unescaped</b> form of the cookie.  You can use the
regular cookie() method to get the names, or use the raw_fetch()
method from the CGI::Cookie module.</p>
</li>
<li><a name="*user_agent()*"></a><b><b>user_agent()</b></b>
<p>Returns the HTTP_USER_AGENT variable.  If you give
this method a single argument, it will attempt to
pattern match on it, allowing you to do something
like user_agent(Mozilla);</p>
</li>
<li><a name="*path_info()*"></a><b><b>path_info()</b></b>
<p>Returns additional path information from the script URL.
E.G. fetching /cgi-bin/your_script/additional/stuff will result in
path_info() returning &quot;/additional/stuff&quot;.</p>
<p>NOTE: The Microsoft Internet Information Server
is broken with respect to additional path information.  If
you use the Perl DLL library, the IIS server will attempt to
execute the additional path information as a Perl script.
If you use the ordinary file associations mapping, the
path information will be present in the environment, 
but incorrect.  The best thing to do is to avoid using additional
path information in CGI scripts destined for use with IIS.</p>
</li>
<li><a name="*path_translated()*"></a><b><b>path_translated()</b></b>
<p>As per path_info() but returns the additional
path information translated into a physical path, e.g.
&quot;/usr/local/etc/httpd/htdocs/additional/stuff&quot;.</p>
<p>The Microsoft IIS is broken with respect to the translated
path as well.</p>
</li>
<li><a name="*remote_host()*"></a><b><b>remote_host()</b></b>
<p>Returns either the remote host name or IP address.
if the former is unavailable.</p>
</li>
<li><a name="*script_name()*-Return-the-script-name-as-a-partial-URL%2c-for-self-refering-scripts."></a><b><b>script_name()</b>
Return the script name as a partial URL, for self-refering
scripts.</b>
</li>
<li><a name="*referer()*"></a><b><b>referer()</b></b>
<p>Return the URL of the page the browser was viewing
prior to fetching your script.  Not available for all
browsers.</p>
</li>
<li><a name="*auth_type-()*"></a><b><b>auth_type ()</b></b>
<p>Return the authorization/verification method in use for this
script, if any.</p>
</li>
<li><a name="*server_name-()*"></a><b><b>server_name ()</b></b>
<p>Returns the name of the server, usually the machine&#39;s host
name.</p>
</li>
<li><a name="*virtual_host-()*"></a><b><b>virtual_host ()</b></b>
<p>When using virtual hosts, returns the name of the host that
the browser attempted to contact</p>
</li>
<li><a name="*server_port-()*"></a><b><b>server_port ()</b></b>
<p>Return the port that the server is listening on.</p>
</li>
<li><a name="*virtual_port-()*"></a><b><b>virtual_port ()</b></b>
<p>Like server_port() except that it takes virtual hosts into account.
Use this when running with virtual hosts.</p>
</li>
<li><a name="*server_software-()*"></a><b><b>server_software ()</b></b>
<p>Returns the server software and version number.</p>
</li>
<li><a name="*remote_user-()*"></a><b><b>remote_user ()</b></b>
<p>Return the authorization/verification name used for user
verification, if this script is protected.</p>
</li>
<li><a name="*user_name-()*"></a><b><b>user_name ()</b></b>
<p>Attempt to obtain the remote user&#39;s name, using a variety of different
techniques.  This only works with older browsers such as Mosaic.
Newer browsers do not report the user name for privacy reasons!</p>
</li>
<li><a name="*request_method()*"></a><b><b>request_method()</b></b>
<p>Returns the method used to access your script, usually
one of &#39;POST&#39;, &#39;GET&#39; or &#39;HEAD&#39;.</p>
</li>
<li><a name="*content_type()*"></a><b><b>content_type()</b></b>
<p>Returns the content_type of data submitted in a POST, generally 
multipart/form-data or application/x-www-form-urlencoded</p>
</li>
<li><a name="*http()*"></a><b><b>http()</b></b>
<p>Called with no arguments returns the list of HTTP environment
variables, including such things as HTTP_USER_AGENT,
HTTP_ACCEPT_LANGUAGE, and HTTP_ACCEPT_CHARSET, corresponding to the
like-named HTTP header fields in the request.  Called with the name of
an HTTP header field, returns its value.  Capitalization and the use
of hyphens versus underscores are not significant.</p>
<p>For example, all three of these examples are equivalent:</p>
<pre class="verbatim"><ol><li>   <span class="i">$requested_language</span> = <span class="i">http</span><span class="s">(</span><span class="q">&#39;Accept-language&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="i">$requested_language</span> = <span class="i">http</span><span class="s">(</span><span class="q">&#39;Accept_language&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   <span class="i">$requested_language</span> = <span class="i">http</span><span class="s">(</span><span class="q">&#39;HTTP_ACCEPT_LANGUAGE&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="*https()*"></a><b><b>https()</b></b>
<p>The same as <i>http()</i>, but operates on the HTTPS environment variables
present when the SSL protocol is in effect.  Can be used to determine
whether SSL is turned on.</p>
</li>
</ul>
<a name="USING-NPH-SCRIPTS"></a><h1>USING NPH SCRIPTS</h1>
<p>NPH, or &quot;no-parsed-header&quot;, scripts bypass the server completely by
sending the complete HTTP header directly to the browser.  This has
slight performance benefits, but is of most use for taking advantage
of HTTP extensions that are not directly supported by your server,
such as server push and PICS headers.</p>
<p>Servers use a variety of conventions for designating CGI scripts as
NPH.  Many Unix servers look at the beginning of the script&#39;s name for
the prefix &quot;nph-&quot;.  The Macintosh WebSTAR server and Microsoft&#39;s
Internet Information Server, in contrast, try to decide whether a
program is an NPH script by examining the first line of script output.</p>
<p>CGI.pm supports NPH scripts with a special NPH mode.  When in this
mode, CGI.pm will output the necessary extra header information when
the header() and redirect() methods are
called.</p>
<p>The Microsoft Internet Information Server requires NPH mode.  As of
version 2.30, CGI.pm will automatically detect when the script is
running under IIS and put itself into this mode.  You do not need to
do this manually, although it won&#39;t hurt anything if you do.  However,
note that if you have applied Service Pack 6, much of the
functionality of NPH scripts, including the ability to redirect while
setting a cookie, <b>do not work at all</b> on IIS without a special patch
from Microsoft.  See
<a href="http://support.microsoft.com/support/kb/articles/Q280/3/41.ASP">http://support.microsoft.com/support/kb/articles/Q280/3/41.ASP</a>:
Non-Parsed Headers Stripped From CGI Applications That Have nph-
Prefix in Name.</p>
<ul>
<li><a name="In-the-*use*-statement"></a><b>In the <b>use</b> statement</b>
<p>Simply add the &quot;-nph&quot; pragmato the list of symbols to be imported into
your script:</p>
<pre class="verbatim"><ol><li>      <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw(:standard -nph)</span></li></ol></pre></li>
<li><a name="By-calling-the-*nph()*-method%3a"></a><b>By calling the <b>nph()</b> method:</b>
<p>Call <b>nph()</b> with a non-zero parameter at any point after using CGI.pm in your program.</p>
<pre class="verbatim"><ol><li>      <span class="w">CGI</span><span class="w">-&gt;nph</span><span class="s">(</span><span class="n">1</span><span class="s">)</span></li></ol></pre></li>
<li><a name="By-using-*-nph*-parameters"></a><b>By using <b>-nph</b> parameters</b>
<p>in the <b>header()</b> and <b>redirect()</b>  statements:</p>
<pre class="verbatim"><ol><li>      <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">nph</span><span class="cm">=&gt;</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
</ul>
<a name="Server-Push"></a><h1>Server Push</h1>
<p>CGI.pm provides four simple functions for producing multipart
documents of the type needed to implement server push.  These
functions were graciously provided by Ed Jordan &lt;ed@fidalgo.net&gt;.  To
import these into your namespace, you must import the &quot;:push&quot; set.
You are also advised to put the script into NPH mode and to set $| to
1 to avoid buffering problems.</p>
<p>Here is a simple script that demonstrates server push:</p>
<pre class="verbatim"><ol><li>  <span class="c">#!/usr/local/bin/perl</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:push -nph/</span><span class="sc">;</span></li><li>  <span class="i">$|</span> = <span class="n">1</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">multipart_init</span><span class="s">(</span>-<span class="w">boundary</span><span class="cm">=&gt;</span><span class="q">&#39;----here we go!&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>  for <span class="s">(</span><span class="n">0</span> .. <span class="n">4</span><span class="s">)</span> <span class="s">{</span></li><li>      <a class="l_k" href="functions/print.html">print</a> <span class="i">multipart_start</span><span class="s">(</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="q">&#39;text/plain&#39;</span><span class="s">)</span><span class="cm">,</span></li><li>            <span class="q">&quot;The current time is &quot;</span><span class="cm">,</span><a class="l_k" href="functions/scalar.html">scalar</a><span class="s">(</span><a class="l_k" href="functions/localtime.html">localtime</a><span class="s">)</span><span class="cm">,</span><span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>      if <span class="s">(</span><span class="i">$_</span> &lt; <span class="n">4</span><span class="s">)</span> <span class="s">{</span></li><li>              <a class="l_k" href="functions/print.html">print</a> <span class="i">multipart_end</span><span class="sc">;</span></li><li>      <span class="s">}</span> else <span class="s">{</span></li><li>              <a class="l_k" href="functions/print.html">print</a> <span class="i">multipart_final</span><span class="sc">;</span></li><li>      <span class="s">}</span></li><li>      <a class="l_k" href="functions/sleep.html">sleep</a> <span class="n">1</span><span class="sc">;</span></li><li>  <span class="s">}</span></li></ol></pre><p>This script initializes server push by calling <b>multipart_init()</b>.
It then enters a loop in which it begins a new multipart section by
calling <b>multipart_start()</b>, prints the current local time,
and ends a multipart section with <b>multipart_end()</b>.  It then sleeps
a second, and begins again. On the final iteration, it ends the
multipart section with <b>multipart_final()</b> rather than with
<b>multipart_end()</b>.</p>
<ul>
<li><a name="multipart_init()"></a><b>multipart_init()</b>
<pre class="verbatim"><ol><li>  <span class="i">multipart_init</span><span class="s">(</span>-<span class="w">boundary</span><span class="cm">=&gt;</span><span class="i">$boundary</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Initialize the multipart system.  The -boundary argument specifies
what MIME boundary string to use to separate parts of the document.
If not provided, CGI.pm chooses a reasonable boundary for you.</p>
</li>
<li><a name="multipart_start()"></a><b>multipart_start()</b>
<pre class="verbatim"><ol><li>  <span class="i">multipart_start</span><span class="s">(</span>-<span class="w">type</span><span class="cm">=&gt;</span><span class="i">$type</span><span class="s">)</span></li></ol></pre><p>Start a new part of the multipart document using the specified MIME
type.  If not specified, text/html is assumed.</p>
</li>
<li><a name="multipart_end()"></a><b>multipart_end()</b>
<pre class="verbatim"><ol><li>  <span class="i">multipart_end</span><span class="s">(</span><span class="s">)</span></li></ol></pre><p>End a part.  You must remember to call multipart_end() once for each
multipart_start(), except at the end of the last part of the multipart
document when multipart_final() should be called instead of multipart_end().</p>
</li>
<li><a name="multipart_final()"></a><b>multipart_final()</b>
<pre class="verbatim"><ol><li>  <span class="i">multipart_final</span><span class="s">(</span><span class="s">)</span></li></ol></pre><p>End all parts.  You should call multipart_final() rather than
multipart_end() at the end of the last part of the multipart document.</p>
</li>
</ul>
<p>Users interested in server push applications should also have a look
at the CGI::Push module.</p>
<a name="Avoiding-Denial-of-Service-Attacks"></a><h1>Avoiding Denial of Service Attacks</h1>
<p>A potential problem with CGI.pm is that, by default, it attempts to
process form POSTings no matter how large they are.  A wily hacker
could attack your site by sending a CGI script a huge POST of many
megabytes.  CGI.pm will attempt to read the entire POST into a
variable, growing hugely in size until it runs out of memory.  While
the script attempts to allocate the memory the system may slow down
dramatically.  This is a form of denial of service attack.</p>
<p>Another possible attack is for the remote user to force CGI.pm to
accept a huge file upload.  CGI.pm will accept the upload and store it
in a temporary directory even if your script doesn&#39;t expect to receive
an uploaded file.  CGI.pm will delete the file automatically when it
terminates, but in the meantime the remote user may have filled up the
server&#39;s disk space, causing problems for other programs.</p>
<p>The best way to avoid denial of service attacks is to limit the amount
of memory, CPU time and disk space that CGI scripts can use.  Some Web
servers come with built-in facilities to accomplish this. In other
cases, you can use the shell <i>limit</i> or <i>ulimit</i>
commands to put ceilings on CGI resource usage.</p>
<p>CGI.pm also has some simple built-in protections against denial of
service attacks, but you must activate them before you can use them.
These take the form of two global variables in the CGI name space:</p>
<ul>
<li><a name="*%24CGI%3a%3aPOST_MAX*"></a><b><b>$CGI::POST_MAX</b></b>
<p>If set to a non-negative integer, this variable puts a ceiling
on the size of POSTings, in bytes.  If CGI.pm detects a POST
that is greater than the ceiling, it will immediately exit with an error
message.  This value will affect both ordinary POSTs and
multipart POSTs, meaning that it limits the maximum size of file
uploads as well.  You should set this to a reasonably high
value, such as 1 megabyte.</p>
</li>
<li><a name="*%24CGI%3a%3aDISABLE_UPLOADS*"></a><b><b>$CGI::DISABLE_UPLOADS</b></b>
<p>If set to a non-zero value, this will disable file uploads
completely.  Other fill-out form values will work as usual.</p>
</li>
</ul>
<p>You can use these variables in either of two ways.</p>
<ul>
<li><a name="*1.-On-a-script-by-script-basis*"></a><b><b>1. On a script-by-script basis</b></b>
<p>Set the variable at the top of the script, right after the &quot;use&quot; statement:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI</span> <span class="q">qw/:standard/</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">CGI::Carp</span> <span class="q">&#39;fatalsToBrowser&#39;</span><span class="sc">;</span></li><li>    <span class="i">$CGI::POST_MAX</span>=<span class="n">1024</span> * <span class="n">100</span><span class="sc">;</span>  <span class="c"># max 100K posts</span></li><li>    <span class="i">$CGI::DISABLE_UPLOADS</span> = <span class="n">1</span><span class="sc">;</span>  <span class="c"># no uploads</span></li></ol></pre></li>
<li><a name="*2.-Globally-for-all-scripts*"></a><b><b>2. Globally for all scripts</b></b>
<p>Open up CGI.pm, find the definitions for $POST_MAX and 
$DISABLE_UPLOADS, and set them to the desired values.  You&#39;ll 
find them towards the top of the file in a subroutine named 
initialize_globals().</p>
</li>
</ul>
<p>An attempt to send a POST larger than $POST_MAX bytes will cause
<i>param()</i> to return an empty CGI parameter list.  You can test for
this event by checking <i>cgi_error()</i>, either after you create the CGI
object or, if you are using the function-oriented interface, call
&lt;param()&gt; for the first time.  If the POST was intercepted, then
cgi_error() will return the message &quot;413 POST too large&quot;.</p>
<p>This error message is actually defined by the HTTP protocol, and is
designed to be returned to the browser as the CGI script&#39;s status
 code.  For example:</p>
<pre class="verbatim"><ol><li>   <span class="i">$uploaded_file</span> = <span class="i">param</span><span class="s">(</span><span class="q">&#39;upload&#39;</span><span class="s">)</span><span class="sc">;</span></li><li>   if <span class="s">(</span>!<span class="i">$uploaded_file</span> &amp;&amp; <span class="i">cgi_error</span><span class="s">(</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>      <a class="l_k" href="functions/print.html">print</a> <span class="i">header</span><span class="s">(</span>-<span class="w">status</span><span class="cm">=&gt;</span><span class="i">cgi_error</span><span class="s">(</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li><li>      <a class="l_k" href="functions/exit.html">exit</a> <span class="n">0</span><span class="sc">;</span></li><li>   <span class="s">}</span></li></ol></pre><p>However it isn&#39;t clear that any browser currently knows what to do
with this status code.  It might be better just to create an
HTML page that warns the user of the problem.</p>
<a name="COMPATIBILITY-WITH-CGI-LIB.PL"></a><h1>COMPATIBILITY WITH CGI-LIB.PL</h1>
<p>To make it easier to port existing programs that use cgi-lib.pl the
compatibility routine &quot;ReadParse&quot; is provided.  Porting is simple:</p>
<p>OLD VERSION
    require &quot;cgi-lib.pl&quot;;
    &amp;ReadParse;
    print &quot;The value of the antique is $in{antique}.\n&quot;;</p>
<p>NEW VERSION
    use CGI;
    CGI::ReadParse();
    print &quot;The value of the antique is $in{antique}.\n&quot;;</p>
<p>CGI.pm&#39;s ReadParse() routine creates a tied variable named %in,
which can be accessed to obtain the query variables.  Like
ReadParse, you can also provide your own variable.  Infrequently
used features of ReadParse, such as the creation of @in and $in 
variables, are not supported.</p>
<p>Once you use ReadParse, you can retrieve the query object itself
this way:</p>
<pre class="verbatim"><ol><li>    <span class="i">$q</span> = <span class="i">$in</span>{<span class="w">CGI</span>}<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">textfield</span><span class="s">(</span>-<span class="w">name</span><span class="cm">=&gt;</span><span class="q">&#39;wow&#39;</span><span class="cm">,</span></li><li>			-<span class="w">value</span><span class="cm">=&gt;</span><span class="q">&#39;does this really work?&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This allows you to start using the more interesting features
of CGI.pm without rewriting your old scripts from scratch.</p>
<a name="AUTHOR-INFORMATION"></a><h1>AUTHOR INFORMATION</h1>
<p>The GD.pm interface is copyright 1995-2007, Lincoln D. Stein.  It is
distributed under GPL and the Artistic License 2.0.</p>
<p>Address bug reports and comments to: lstein@cshl.org.  When sending
bug reports, please provide the version of CGI.pm, the version of
Perl, the name and version of your Web server, and the name and
version of the operating system you are using.  If the problem is even
remotely browser dependent, please provide information about the
affected browers as well.</p>
<a name="CREDITS"></a><h1>CREDITS</h1>
<p>Thanks very much to:</p>
<ul>
<li><a name="Matt-Heffron-(heffron%40falstaff.css.beckman.com)"></a><b>Matt Heffron (heffron@falstaff.css.beckman.com)</b>
</li>
<li><a name="James-Taylor-(james.taylor%40srs.gov)"></a><b>James Taylor (james.taylor@srs.gov)</b>
</li>
<li><a name="Scott-Anguish-%3csanguish%40digifix.com%3e"></a><b>Scott Anguish &lt;sanguish@digifix.com&gt;</b>
</li>
<li><a name="Mike-Jewell-(mlj3u%40virginia.edu)"></a><b>Mike Jewell (mlj3u@virginia.edu)</b>
</li>
<li><a name="Timothy-Shimmin-(tes%40kbs.citri.edu.au)"></a><b>Timothy Shimmin (tes@kbs.citri.edu.au)</b>
</li>
<li><a name="Joergen-Haegg-(jh%40axis.se)"></a><b>Joergen Haegg (jh@axis.se)</b>
</li>
<li><a name="Laurent-Delfosse-(delfosse%40delfosse.com)"></a><b>Laurent Delfosse (delfosse@delfosse.com)</b>
</li>
<li><a name="Richard-Resnick-(applepi1%40aol.com)"></a><b>Richard Resnick (applepi1@aol.com)</b>
</li>
<li><a name="Craig-Bishop-(csb%40barwonwater.vic.gov.au)"></a><b>Craig Bishop (csb@barwonwater.vic.gov.au)</b>
</li>
<li><a name="Tony-Curtis-(tc%40vcpc.univie.ac.at)"></a><b>Tony Curtis (tc@vcpc.univie.ac.at)</b>
</li>
<li><a name="Tim-Bunce-(Tim.Bunce%40ig.co.uk)"></a><b>Tim Bunce (Tim.Bunce@ig.co.uk)</b>
</li>
<li><a name="Tom-Christiansen-(tchrist%40convex.com)"></a><b>Tom Christiansen (tchrist@convex.com)</b>
</li>
<li><a name="Andreas-Koenig-(k%40franz.ww.TU-Berlin.DE)"></a><b>Andreas Koenig (k@franz.ww.TU-Berlin.DE)</b>
</li>
<li><a name="Tim-MacKenzie-(Tim.MacKenzie%40fulcrum.com.au)"></a><b>Tim MacKenzie (Tim.MacKenzie@fulcrum.com.au)</b>
</li>
<li><a name="Kevin-B.-Hendricks-(kbhend%40dogwood.tyler.wm.edu)"></a><b>Kevin B. Hendricks (kbhend@dogwood.tyler.wm.edu)</b>
</li>
<li><a name="Stephen-Dahmen-(joyfire%40inxpress.net)"></a><b>Stephen Dahmen (joyfire@inxpress.net)</b>
</li>
<li><a name="Ed-Jordan-(ed%40fidalgo.net)"></a><b>Ed Jordan (ed@fidalgo.net)</b>
</li>
<li><a name="David-Alan-Pisoni-(david%40cnation.com)"></a><b>David Alan Pisoni (david@cnation.com)</b>
</li>
<li><a name="Doug-MacEachern-(dougm%40opengroup.org)"></a><b>Doug MacEachern (dougm@opengroup.org)</b>
</li>
<li><a name="Robin-Houston-(robin%40oneworld.org)"></a><b>Robin Houston (robin@oneworld.org)</b>
</li>
<li><a name="...and-many-many-more..."></a><b>...and many many more...</b>
<p>for suggestions and bug fixes.</p>
</li>
</ul>
<a name="A-COMPLETE-EXAMPLE-OF-A-SIMPLE-FORM-BASED-SCRIPT"></a><h1>A COMPLETE EXAMPLE OF A SIMPLE FORM-BASED SCRIPT</h1>
<pre class="verbatim"><ol><li>	#!/usr/local/bin/perl</li><li></li><li>	use CGI ':standard';</li><li></li><li>	print header;</li><li>	print start_html("Example CGI.pm Form");</li><li>	print "&lt;h1&gt; Example CGI.pm Form&lt;/h1&gt;\n";</li><li>        print_prompt();</li><li>	do_work();</li><li>	print_tail();</li><li>	print end_html;</li><li></li><li>	sub print_prompt {</li><li>	   print start_form;</li><li>	   print "&lt;em&gt;What's your name?&lt;/em&gt;&lt;br&gt;";</li><li>	   print textfield('name');</li><li>	   print checkbox('Not my real name');</li><li></li><li>	   print "&lt;p&gt;&lt;em&gt;Where can you find English Sparrows?&lt;/em&gt;&lt;br&gt;";</li><li>	   print checkbox_group(</li><li>				 -name=&gt;'Sparrow locations',</li><li>				 -values=&gt;[England,France,Spain,Asia,Hoboken],</li><li>				 -linebreak=&gt;'yes',</li><li>				 -defaults=&gt;[England,Asia]);</li><li></li><li>	   print "&lt;p&gt;&lt;em&gt;How far can they fly?&lt;/em&gt;&lt;br&gt;",</li><li>		radio_group(</li><li>			-name=&gt;'how far',</li><li>			-values=&gt;['10 ft','1 mile','10 miles','real far'],</li><li>			-default=&gt;'1 mile');</li><li></li><li>	   print "&lt;p&gt;&lt;em&gt;What's your favorite color?&lt;/em&gt;  ";</li><li>	   print popup_menu(-name=&gt;'Color',</li><li>				    -values=&gt;['black','brown','red','yellow'],</li><li>				    -default=&gt;'red');</li><li></li><li>	   print hidden('Reference','Monty Python and the Holy Grail');</li><li></li><li>	   print "&lt;p&gt;&lt;em&gt;What have you got there?&lt;/em&gt;&lt;br&gt;";</li><li>	   print scrolling_list(</li><li>			 -name=&gt;'possessions',</li><li>			 -values=&gt;['A Coconut','A Grail','An Icon',</li><li>				   'A Sword','A Ticket'],</li><li>			 -size=&gt;5,</li><li>			 -multiple=&gt;'true');</li><li></li><li>	   print "&lt;p&gt;&lt;em&gt;Any parting comments?&lt;/em&gt;&lt;br&gt;";</li><li>	   print textarea(-name=&gt;'Comments',</li><li>				  -rows=&gt;10,</li><li>				  -columns=&gt;50);</li><li></li><li>	   print "&lt;p&gt;",reset;</li><li>	   print submit('Action','Shout');</li><li>	   print submit('Action','Scream');</li><li>	   print endform;</li><li>	   print "&lt;hr&gt;\n";</li><li>	}</li><li></li><li>	sub do_work {</li><li>	   my(@values,$key);</li><li></li><li>	   print "&lt;h2&gt;Here are the current settings in this form&lt;/h2&gt;";</li><li></li><li>	   for $key (param) {</li><li>	      print "&lt;strong&gt;$key&lt;/strong&gt; -&gt; ";</li><li>	      @values = param($key);</li><li>	      print join(", ",@values),"&lt;br&gt;\n";</li><li>	  }</li><li>	}</li><li></li><li>	sub print_tail {</li><li>	   print &lt;&lt;END;</li><li>	&lt;hr&gt;</li><li>	&lt;address&gt;Lincoln D. Stein&lt;/address&gt;&lt;br&gt;</li><li>	&lt;a href="/"&gt;Home Page&lt;/a&gt;</li><li>	END</li><li>	}</li></ol></pre><a name="BUGS"></a><h1>BUGS</h1>
<p>Please report them.</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="CGI/Carp.html">CGI::Carp</a>, <a href="CGI/Fast.html">CGI::Fast</a>, <a href="CGI/Pretty.html">CGI::Pretty</a></p>




  <div id="page_index">
    <div id="page_index_header">
      <div id="page_index_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title"><span class="page_index_top">Page index</span></div>
      <div id="page_index_topright"></div>
    </div>
    <div id="page_index_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#PROGRAMMING-STYLE">PROGRAMMING STYLE</a><li><a href="#CALLING-CGI.PM-ROUTINES">CALLING CGI.PM ROUTINES</a><li><a href="#CREATING-A-NEW-QUERY-OBJECT-(OBJECT-ORIENTED-STYLE)%3a">CREATING A NEW QUERY OBJECT (OBJECT-ORIENTED STYLE):</a><li><a href="#CREATING-A-NEW-QUERY-OBJECT-FROM-AN-INPUT-FILE">CREATING A NEW QUERY OBJECT FROM AN INPUT FILE</a><li><a href="#FETCHING-A-LIST-OF-KEYWORDS-FROM-THE-QUERY%3a">FETCHING A LIST OF KEYWORDS FROM THE QUERY:</a><li><a href="#FETCHING-THE-NAMES-OF-ALL-THE-PARAMETERS-PASSED-TO-YOUR-SCRIPT%3a">FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:</a><li><a href="#FETCHING-THE-VALUE-OR-VALUES-OF-A-SINGLE-NAMED-PARAMETER%3a">FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER:</a><li><a href="#SETTING-THE-VALUE(S)-OF-A-NAMED-PARAMETER%3a">SETTING THE VALUE(S) OF A NAMED PARAMETER:</a><li><a href="#APPENDING-ADDITIONAL-VALUES-TO-A-NAMED-PARAMETER%3a">APPENDING ADDITIONAL VALUES TO A NAMED PARAMETER:</a><li><a href="#IMPORTING-ALL-PARAMETERS-INTO-A-NAMESPACE%3a">IMPORTING ALL PARAMETERS INTO A NAMESPACE:</a><li><a href="#DELETING-A-PARAMETER-COMPLETELY%3a">DELETING A PARAMETER COMPLETELY:</a><li><a href="#DELETING-ALL-PARAMETERS%3a">DELETING ALL PARAMETERS:</a><li><a href="#HANDLING-NON-URLENCODED-ARGUMENTS">HANDLING NON-URLENCODED ARGUMENTS</a><li><a href="#DIRECT-ACCESS-TO-THE-PARAMETER-LIST%3a">DIRECT ACCESS TO THE PARAMETER LIST:</a><li><a href="#FETCHING-THE-PARAMETER-LIST-AS-A-HASH%3a">FETCHING THE PARAMETER LIST AS A HASH:</a><li><a href="#SAVING-THE-STATE-OF-THE-SCRIPT-TO-A-FILE%3a">SAVING THE STATE OF THE SCRIPT TO A FILE:</a><li><a href="#RETRIEVING-CGI-ERRORS">RETRIEVING CGI ERRORS</a><li><a href="#USING-THE-FUNCTION-ORIENTED-INTERFACE">USING THE FUNCTION-ORIENTED INTERFACE</a><li><a href="#PRAGMAS">PRAGMAS</a><li><a href="#SPECIAL-FORMS-FOR-IMPORTING-HTML-TAG-FUNCTIONS">SPECIAL FORMS FOR IMPORTING HTML-TAG FUNCTIONS</a></ul><li><a href="#GENERATING-DYNAMIC-DOCUMENTS">GENERATING DYNAMIC DOCUMENTS</a><ul><li><a href="#CREATING-A-STANDARD-HTTP-HEADER%3a">CREATING A STANDARD HTTP HEADER:</a><li><a href="#GENERATING-A-REDIRECTION-HEADER">GENERATING A REDIRECTION HEADER</a><li><a href="#CREATING-THE-HTML-DOCUMENT-HEADER">CREATING THE HTML DOCUMENT HEADER</a><li><a href="#ENDING-THE-HTML-DOCUMENT%3a">ENDING THE HTML DOCUMENT:</a><li><a href="#CREATING-A-SELF-REFERENCING-URL-THAT-PRESERVES-STATE-INFORMATION%3a">CREATING A SELF-REFERENCING URL THAT PRESERVES STATE INFORMATION:</a><li><a href="#OBTAINING-THE-SCRIPT'S-URL">OBTAINING THE SCRIPT'S URL</a><li><a href="#MIXING-POST-AND-URL-PARAMETERS">MIXING POST AND URL PARAMETERS</a></ul><li><a href="#CREATING-STANDARD-HTML-ELEMENTS%3a">CREATING STANDARD HTML ELEMENTS:</a><ul><li><a href="#PROVIDING-ARGUMENTS-TO-HTML-SHORTCUTS">PROVIDING ARGUMENTS TO HTML SHORTCUTS</a><li><a href="#THE-DISTRIBUTIVE-PROPERTY-OF-HTML-SHORTCUTS">THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS</a><li><a href="#HTML-SHORTCUTS-AND-LIST-INTERPOLATION">HTML SHORTCUTS AND LIST INTERPOLATION</a><li><a href="#NON-STANDARD-HTML-SHORTCUTS">NON-STANDARD HTML SHORTCUTS</a><li><a href="#AUTOESCAPING-HTML">AUTOESCAPING HTML</a><li><a href="#PRETTY-PRINTING-HTML">PRETTY-PRINTING HTML</a></ul><li><a href="#CREATING-FILL-OUT-FORMS%3a">CREATING FILL-OUT FORMS:</a><ul><li><a href="#CREATING-AN-ISINDEX-TAG">CREATING AN ISINDEX TAG</a><li><a href="#STARTING-AND-ENDING-A-FORM">STARTING AND ENDING A FORM</a><li><a href="#FORM-ELEMENTS">FORM ELEMENTS</a><li><a href="#CREATING-A-TEXT-FIELD">CREATING A TEXT FIELD</a><li><a href="#CREATING-A-BIG-TEXT-FIELD">CREATING A BIG TEXT FIELD</a><li><a href="#CREATING-A-PASSWORD-FIELD">CREATING A PASSWORD FIELD</a><li><a href="#CREATING-A-FILE-UPLOAD-FIELD">CREATING A FILE UPLOAD FIELD</a><li><a href="#CREATING-A-POPUP-MENU">CREATING A POPUP MENU</a><li><a href="#CREATING-AN-OPTION-GROUP">CREATING AN OPTION GROUP</a><li><a href="#CREATING-A-SCROLLING-LIST">CREATING A SCROLLING LIST</a><li><a href="#CREATING-A-GROUP-OF-RELATED-CHECKBOXES">CREATING A GROUP OF RELATED CHECKBOXES</a><li><a href="#CREATING-A-STANDALONE-CHECKBOX">CREATING A STANDALONE CHECKBOX</a><li><a href="#CREATING-A-RADIO-BUTTON-GROUP">CREATING A RADIO BUTTON GROUP</a><li><a href="#CREATING-A-SUBMIT-BUTTON">CREATING A SUBMIT BUTTON</a><li><a href="#CREATING-A-RESET-BUTTON">CREATING A RESET BUTTON</a><li><a href="#CREATING-A-DEFAULT-BUTTON">CREATING A DEFAULT BUTTON</a><li><a href="#CREATING-A-HIDDEN-FIELD">CREATING A HIDDEN FIELD</a><li><a href="#CREATING-A-CLICKABLE-IMAGE-BUTTON">CREATING A CLICKABLE IMAGE BUTTON</a><li><a href="#CREATING-A-JAVASCRIPT-ACTION-BUTTON">CREATING A JAVASCRIPT ACTION BUTTON</a></ul><li><a href="#HTTP-COOKIES">HTTP COOKIES</a><li><a href="#WORKING-WITH-FRAMES">WORKING WITH FRAMES</a><li><a href="#SUPPORT-FOR-JAVASCRIPT">SUPPORT FOR JAVASCRIPT</a><li><a href="#LIMITED-SUPPORT-FOR-CASCADING-STYLE-SHEETS">LIMITED SUPPORT FOR CASCADING STYLE SHEETS</a><li><a href="#DEBUGGING">DEBUGGING</a><ul><li><a href="#DUMPING-OUT-ALL-THE-NAME%2fVALUE-PAIRS">DUMPING OUT ALL THE NAME/VALUE PAIRS</a></ul><li><a href="#FETCHING-ENVIRONMENT-VARIABLES">FETCHING ENVIRONMENT VARIABLES</a><li><a href="#USING-NPH-SCRIPTS">USING NPH SCRIPTS</a><li><a href="#Server-Push">Server Push</a><li><a href="#Avoiding-Denial-of-Service-Attacks">Avoiding Denial of Service Attacks</a><li><a href="#COMPATIBILITY-WITH-CGI-LIB.PL">COMPATIBILITY WITH CGI-LIB.PL</a><li><a href="#AUTHOR-INFORMATION">AUTHOR INFORMATION</a><li><a href="#CREDITS">CREDITS</a><li><a href="#A-COMPLETE-EXAMPLE-OF-A-SIMPLE-FORM-BASED-SCRIPT">A COMPLETE EXAMPLE OF A SIMPLE FORM-BASED SCRIPT</a><li><a href="#BUGS">BUGS</a><li><a href="#SEE-ALSO">SEE ALSO</a></ul>
    </div>
    <div id="page_index_footer">
      <div id="page_index_bottomleft"></div>
      <div id="page_index_bottom"><span class="page_index_bottom"></span></div>
      <div id="page_index_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div id="right_column">
          <div class="side_group">
	    
              <script language="JavaScript" type="text/javascript">
function selectPerlVersion(element) {
  if (element.value.substring(0,1) == '/') {
    location.href = element.value;
  }
}
</script>
            <div class="side_panel tools_panel">
              <p>Perl version</p>
<select id="perl_version_select" name="version-chooser" onChange="selectPerlVersion(this)">
  <option selected>Select...
  <option>Perl 5 version 10
    <option value="/index.html">&nbsp;&nbsp;&bull;&nbsp;Perl 5.10.1
    <option value="/5.10.0/index.html">&nbsp;&nbsp;&bull;&nbsp;Perl 5.10.0
  <option>
  <option>Perl 5 version 8
    <option value="/5.8.9/index.html">&nbsp;&nbsp;&bull;&nbsp;Perl 5.8.9
    <option value="/5.8.8/index.html">&nbsp;&nbsp;&bull;&nbsp;Perl 5.8.8
</select>
</div>

	    
            <div class="side_panel tools_panel">
              <p>Recently read</p>
              <div id="recent_pages"></div>
            </div>
            <div class="side_panel tools_panel">
              <p>Tools</p>
              <ul>
		<li><a href="preferences.html">Preferences</a>
              </ul>
            </div>
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
      <div id="footer">
	<div id="footer_content">
	  
	</div>
      </div>
      
    </div>
      <script language="JavaScript" src="/static/combined-20090809.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 'CGI';
  perldoc.pageAddress = 'CGI.html';
  perldoc.contentPage = 1;
</script>
    
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTrackerJJ = _gat._getTracker("UA-1892152-2");
pageTrackerJJ._initData();
pageTrackerJJ._trackPageview();
var pageTrackerRobert = _gat._getTracker("UA-50555-3");
pageTrackerRobert._initData();
pageTrackerRobert._trackPageview();
</script>
    
  </body>
</html>
